#include <iostream>
using namespace std;
const int N = 1e6 + 1;
int n, first[N], mx = 1;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n;
for (int i = 0; i < N; ++i)
first[i] = -1;
for (int a, i = 0; i < n; ++i) {
cin >> a;
a += 5e5;
if (first[a] == -1) {
first[a] = i;
}
else {
mx = max(mx, i - first[a] + 1);
}
}
cout << mx << endl;
}