#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.fr >> a.sc;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.fr << " " << a.sc;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const long long N = 0;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 1, cnt = 0;
  long long ans1 = 0;
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] == 1) {
        ans = a[i];
        cnt++;
      } else
        ans = a[i];
    } else if (a[i] == ans + 1) {
      cnt++;
      ans = a[i];
    } else {
      ans1 = max(ans1, cnt);
      cnt = 0;
      ans = a[i];
    }
  }
  ans1 = max(ans1, cnt);
  long long cnt1 = 999;
  long long ans2 = n - 1;
  for (long long i = n - 2; i >= 0; i--) {
    if (cnt1 == a[i]) {
      ans2 = i;
    }
    cnt1 = cnt1 - 1;
  }
  long long k = n - 1 - ans2;
  cout << max(ans1 - 1, k) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) solve();
  return 0;
}
