#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
int n,m;
vector<int> ds;
set<int> ans;
void print(vector<int> &a){
for(int x : a)
cout<<x<<" ";
cout<<"\n";
}
void go(vector<int> &a, int idx){
if(idx == a.size()){
bool same= 1;
for(int i = 1; i < a.size(); i++){
same &= (a[i] == a[i - 1]);
}
if(same) ans.insert(a[0]);
return;
}
for(int d = 0; d < m; d++){
int nxt= (idx + 1) % n;
int x= a[idx];
int y= a[nxt];
a[idx] = (a[idx] + d) % m;
a[nxt] = (a[nxt] - d + m) % m;
ds.push_back(d);
go(a, idx + 1);
ds.pop_back();
a[idx] = x;
a[nxt] = y;
}
}
int main(){
cin.tie(0);
cin.sync_with_stdio(0);
long long n, m;
cin>>n>>m;
long long sum = 0;
long long a[n];
for(int i = 0; i < n; i++){
cin>>a[i];
sum += a[i] % n;
sum %= n;
}
if(sum == 0){
cout<<__gcd(n, m)<<"\n";
}else{
cout<<"0\n";
}
}
Copy