#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k, l, p;
  cin >> n;
  int a[n + 2];
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ans = 0;
  int tek = 0;
  if (n > 1)
    if (a[0] == 1 && a[1] == 2) ++tek;
  for (int i = 1; i < n - 1; ++i)
    if (a[i - 1] + 1 == a[i] && a[i + 1] - 1 == a[i])
      ++tek;
    else {
      ans = max(ans, tek);
      tek = 0;
    }
  if (n > 1)
    if (a[n - 1] == 1000 && a[n - 2] == 999) ++tek;
  cout << max(ans, tek);
}
