#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  int ans = 0;
  a[0] = a[1] - 1;
  int len = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1] + 1)
      len++;
    else
      len = 1;
    ans = max(ans, len);
  }
  ans -= 2;
  int k = 1;
  if (a[1] == 1)
    while (k <= n && a[k] == a[k - 1] + 1) k++;
  k--;
  ans = max(ans, k - 1);
  k = n;
  a[n + 1] = a[n] + 1;
  if (a[n] == 1000)
    while (k && a[k] + 1 == a[k + 1]) k--;
  k++;
  ans = max(ans, n - k);
  ans = max(0, ans);
  printf("%d\n", ans);
  return 0;
}
