#include <bits/stdc++.h>
using namespace std;
const int dell[8][2] = {{1, 2},  {1, -2},  {2, 1},  {2, -1},
                        {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}};
long long mod = 1e9 + 7;
const long long inf = (1LL << 31) - 1;
const int maxn = 3e5 + 7;
const int maxm = 2e7 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int csize = 22;
int n, m, k, ar[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
  }
  int ans = 0;
  int i = 1;
  while (i <= n) {
    int x = i + 1;
    while (x <= n && ar[x] == ar[x - 1] + 1) {
      x++;
    }
    x--;
    int e = 0;
    if (ar[i] == 1) e++;
    if (ar[x] == 1000) e++;
    ans = max(ans, x - i - 1 + e);
    i = x + 1;
  }
  printf("%d\n", ans);
  return 0;
}
