#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
signed main() {
  long long i, n;
  cin >> n;
  vector<long long> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long len = 1; len <= n; len++) {
    for (long long l = 0; l <= n - len; l++) {
      long long r = l + len - 1;
      if (l == 0 && r == n - 1) {
        continue;
      }
      if (l == 0) {
        if (a[r + 1] == len + 1) {
          ans = max(ans, len);
        }
      } else if (r == n - 1) {
        if (a[l - 1] == 1000 - len) {
          ans = max(ans, len);
        }
      } else {
        if (a[l - 1] == a[r + 1] - len - 1) {
          ans = max(ans, len);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
