#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18;
const double eps = 1e-9;
long long mod = 998244353;
const long long M = 1e5 + 5;
const long long N = 1e6 + 5;
long long n;
long long a[N];
long long ans = 0;
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  long long t = -1;
  for (long long i = 2; i <= n; i++)
    if (a[i] - a[i - 1] > 1)
      t = -1;
    else
      t++, (ans) = (ans) >= (t) ? (ans) : (t);
  t = 0;
  for (long long i = 1; i <= n; i++)
    if (a[i] == i)
      t++;
    else
      break;
  (ans) = (ans) >= (t - 1) ? (ans) : (t - 1);
  t = 0;
  for (long long i = n; i >= 1; i--)
    if (a[i] == 1000 - (n - i))
      t++;
    else
      break;
  (ans) = (ans) >= (t - 1) ? (ans) : (t - 1);
  cout << ans;
}
