#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
const int K = (1 << 17) + 10;
const long long int INF = 2e18 + 500;
const int inf = 0x7fffffff;
const int SQRT = 500;
const int lgN = 20;
int A[N], l[N];
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  assert(n <= 100);
  for (int i = 1; i <= n; i++) cin >> A[i];
  int ans = 0;
  int ind = -1;
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      l[i] = 1;
    else {
      if (A[i] == A[i - 1] + 1)
        l[i] = l[i - 1] + 1;
      else
        l[i] = 1;
    }
    if (l[i] > ans) {
      ans = l[i];
      ind = i;
    } else if (l[i] == ans) {
      if (A[i] == 1000) {
        ans = l[i];
        ind = i;
      }
    }
  }
  if (ans <= 1)
    cout << "0\n";
  else if (ans == 2) {
    if (ans == A[ind] || A[ind] == 1000) {
      cout << ans - 1;
    } else
      cout << 0 << endl;
  } else if (A[ind] != 1000) {
    if (A[ind] == ans)
      cout << ans - 1 << endl;
    else
      cout << ans - 2 << endl;
  } else {
    cout << ans - 1 << endl;
  }
  return 0;
}
