#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 100010, M = N * 2;
const double PI = 3.1415926;
long long n, k, m;
int a[N];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
  cin >> n;
  int mx = 0;
  a[0] = 0;
  a[n + 1] = 1001;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= i; j++) {
      if (a[i] - i == a[j] - j) {
        mx = max(mx, i - j - 1);
      }
    }
  }
  cout << mx << endl;
}
int main() {
  int T = 1;
  while (T--) solve();
}
