#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  if (a[0] == 1) {
    a[n++] = 0;
    sort(a, a + n);
  }
  if (a[n - 1] == 1000) a[n++] = 1001;
  int u = 0;
  for (int i = 0; i < n; i++) {
    int q = 0;
    for (int j = i + 2; j < n; j++)
      if (a[j] - a[i] == j - i) q++;
    u = max(u, q);
  }
  cout << u;
  return 0;
}
