#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;
}
