#include <bits/stdc++.h>
using namespace std;
int a[1500];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  a[0] = 0;
  a[n + 1] = 1001;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = i + 2; j <= n + 1; j++) {
      if (a[j] - a[i] == j - i) {
        ans = max(ans, j - i - 1);
      }
    }
  }
  cout << ans;
}
