#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
inline int power(int a, int b) {
int x = 1;
while (b) {
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}
const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;
//_ ***************************** START Below *******************************
//? Intuition :
//* Explore all consecutive sequence starting from x
//* How to find starting point x of any k-th consecutive seq ?
//* If x-1 is not in array, then x is starting point of k-th seq
//* Eg : [ 0 10 2 1 3 4 11 5 8 12 6 7 13 ]
//* seq :
//* 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
//* 10 -> 11 -> 12 -> 13
//* 0 & 10 are starting point bcz -1 && 9 are not present in array
vector<int> a;
void consistency(int n) {
unordered_set<int> visited;
unordered_set<int> isPresent;
for(int i=0; i<n; i++){
isPresent.insert(a[i]);
}
int maxLen = 0;
for(auto& val : a){
if(visited.count(val)) continue;
if(isPresent.count(val-1)) continue;
int startP = val;
int len = 0;
while(isPresent.count(startP)){
visited.insert(startP);
startP++;
len++;
}
maxLen = max(maxLen, len);
}
cout << maxLen << endl;
}
void solve() {
int n;
cin >> n;
a.resize(n);
for(int i=0; i<n; i++) cin >> a[i];
consistency(n) ;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}