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