#include <bits/stdc++.h>
using namespace std;
const int maxn=1e7+14;
long long n, pre[maxn], k;
int ans = -1;
void solve(){
cin >> n >> k;
pre[0] = 0;
unordered_map < long long , int > m;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
pre[i] = (pre[i - 1] + x) % k;
if (!m[pre[i]]) m[pre[i]] = i;
}
m[0] = 0;
for (int i = 1; i <= n; i++) {
if (pre[i] == 0) ans = max(ans, i);
if (m[pre[i]]){
ans = max(ans, i - m[pre[i]]);
}
}
if (ans == 0 ){
cout << -1 ;
return ;
}
cout << ans ;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("input.txt","r")){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuPTFlNysxNDsKbG9uZyBsb25nIG4sIHByZVttYXhuXSwgazsKaW50IGFucyA9IC0xOwp2b2lkIHNvbHZlKCl7CgljaW4gPj4gbiA+PiBrOwoJcHJlWzBdID0gMDsKCXVub3JkZXJlZF9tYXAgPCBsb25nIGxvbmcgLCBpbnQgPiBtOwoJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKXsKCQlpbnQgeDsKCQljaW4gPj4geDsKCQlwcmVbaV0gPSAocHJlW2kgLSAxXSArIHgpICUgazsKCQlpZiAoIW1bcHJlW2ldXSkgbVtwcmVbaV1dID0gaTsKCX0KCW1bMF0gPSAwOwoJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgaWYgKHByZVtpXSA9PSAwKSBhbnMgPSBtYXgoYW5zLCBpKTsKCQlpZiAobVtwcmVbaV1dKXsKCQkJYW5zID0gbWF4KGFucywgaSAtIG1bcHJlW2ldXSk7CgkJfQoJfQoJaWYgKGFucyA9PSAwICl7CgkJY291dCA8PCAtMSA7CgkJcmV0dXJuIDsKCX0KCQoJY291dCA8PCBhbnMgOwp9CmludCBtYWluKCl7Cglpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwoJY2luLnRpZSgwKTsgICAgY291dC50aWUoMCk7CiAgICBpZiAoZm9wZW4oImlucHV0LnR4dCIsInIiKSl7CiAgICAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwogICAgICAgIGZyZW9wZW4oIm91dHB1dC50eHQiLCJ3IixzdGRvdXQpOwogICAgfQoJc29sdmUoKTsKCXJldHVybiAwOwp9Cg==