#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second > b.second)
    return true;
  else if (a.second == b.second)
    return a.first > b.first;
  else
    return false;
}
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ma = 0;
  if (a[n - 1] == n)
    ma = max(ma, n - 1);
  else if (a[0] == 1000 - (n - 1))
    ma = max(ma, n - 1);
  else {
    for (long long i = 1; i < n; i++) {
      if (a[i] == i + 1) ma = max(ma, i);
    }
    for (long long i = 0; i < n - 1; i++) {
      if (a[i] == 1000 - (n - 1 - i)) ma = max(ma, n - 1 - i);
    }
    for (long long i = 0; i < n - 1; i++) {
      long long j = -1;
      for (j = i + 1; j < n; j++) {
        if (a[j] - a[j - 1] != 1) break;
      }
      if (j != -1) ma = max(ma, j - i - 2);
    }
  }
  cout << ma;
}
