#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)9e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> A(n + 2);
  A[0] = 0;
  A[n + 1] = 1001;
  for (long long i = 1; i <= n; i++) cin >> A[i];
  long long cnt = 0;
  long long cntm = 0;
  for (long long i = 1; i <= n; i++) {
    if (cnt > 0) {
      if (A[i - 1] + 1 == A[i] && A[i + 1] == A[i] + 1)
        cnt++;
      else {
        if (cnt > cntm) cntm = cnt;
        cnt = 0;
      }
    } else {
      if (A[i - 1] + 1 == A[i] && A[i + 1] == A[i] + 1) cnt++;
    }
  }
  cout << max(cnt, cntm);
  return 0;
}
