#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T>& operator--(vector<T>& v) {
  for (auto& i : v) --i;
  return v;
}
template <typename T>
vector<T>& operator++(vector<T>& v) {
  for (auto& i : v) ++i;
  return v;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto& i : v) os << i << ' ';
  return os;
}
template <typename T, typename U>
pair<T, U>& operator--(pair<T, U>& p) {
  --p.first;
  --p.second;
  return p;
}
template <typename T, typename U>
pair<T, U>& operator++(pair<T, U>& p) {
  ++p.first;
  ++p.second;
  return p;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U> p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return mp(a.first - b.first, a.second - b.second);
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return mp(a.first + b.first, a.second + b.second);
}
template <typename T, typename U>
void umin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void umax(T& a, U b) {
  if (a < b) a = b;
}
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long fact(long long x) {
  long long ans = 1;
  for (long long i = 2; i <= x; i++) ans *= i;
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  cin >> a;
  if (n == 1) {
    cout << 0 << endl;
    return;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long cnt = 0;
    if ((i == 0 && a[i + 1] == 2) || (i == n - 1 && a[i - 1] == 999) ||
        (i > 0 && i + 1 < n && a[i + 1] - a[i - 1] == 2)) {
      while (i < n) {
        if (i == 0) {
          if (a[i + 1] == 2) {
            cnt++;
            i++;
          } else {
            break;
          }
        } else if (i == n - 1) {
          if (a[i - 1] == 999) {
            cnt++;
            i++;
          } else {
            break;
          }
        } else {
          if (a[i + 1] - a[i - 1] == 2) {
            cnt++;
            i++;
          } else {
            break;
          }
        }
      }
      i--;
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
