#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int i = 0;
  int m = 0;
  int ind1, ind2, flag = 0;
  while (i < n) {
    cin >> a[i];
    i++;
  }
  i = 0;
  int ans = 0;
  while (i < n) {
    ans = 1;
    while (i < n - 1 and a[i] == a[i + 1] - 1) {
      ans++;
      i++;
    }
    if (ans >= m) {
      flag = 1;
      m = ans;
      ind1 = i;
      ind2 = ind1 - (ans - 1);
    }
    i++;
  }
  int kk = m;
  m -= 2;
  if (m < 0) m = 0;
  swap(ind1, ind2);
  ind1++;
  ind2--;
  i = 0;
  flag = 0;
  int foo = 0;
  while (n > 2 and ind1 != 1 and ind2 == n - 2 and i < kk - 1 and a[1] == 2 and
         a[n - 2] != 999) {
    foo = 1;
    if (a[i + 1] != a[i] + 1) flag = 1;
    i++;
  }
  if (flag == 0 and foo == 1) m++;
  if (n > 1 and a[1] == 2 and ind1 == 1) m++;
  if (n > 1 and a[n - 2] == 999 and ind2 == n - 2) m++;
  cout << m;
}
