#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 100;
int a[MAXN];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for (int s = 1; s <= n; s++) {
    for (int l = 1; l <= n; l++) {
      int e = s + l - 1;
      if (s == 1) {
        if (a[e + 1] == l + 1) ans = max(ans, l);
      } else if (e == n) {
        if (a[s - 1] == 1000 - l) ans = max(ans, l);
      } else {
        if (a[e + 1] - a[s - 1] == l + 1) ans = max(ans, l);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
