#include <bits/stdc++.h>
using namespace std;
void solve(void);
int main() {
  {
    { solve(); }
  }
  return 0;
}
void solve() {
  long long int n, cnt = 0, ans = 0, i, j, mx = 0;
  cin >> n;
  long long int a[n + 1];
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    j = n - i;
    if (a[i] == 1000 - j) {
      ans = j;
      mx = max(ans, mx);
    } else if (a[i] == a[i - 1] + 1 && i > 1) {
      cnt++;
    } else if (a[i] != a[i - 1] + 1 && i > 1) {
      ans = max(cnt - 1, 0ll);
      mx = max(ans, mx);
      cnt = 0;
    }
  }
  if (cnt != 0) {
    ans = max(cnt - 1, 0ll);
    mx = max(ans, mx);
  }
  for (i = n; i >= 2; i--) {
    if (a[i] == i) {
      ans = i - 1;
      mx = max(ans, mx);
      break;
    }
  }
  cout << mx << endl;
}
