#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define clr(v,d) memset(v,d,sizeof(v));
#define pi acos(-1)
const int N = 2475000;
const ll mod = 1e9 + 7;
int main()
{
cin.tie(0);
cin.sync_with_stdio(0);
ll n , m;
cin >> n >> m;
ll a[n] , sum = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i] ;
sum += a[i];
sum %= __gcd(n,m);
}
if(sum) cout << 0 ;
else cout << __gcd(n,m);
return 0;
}