#include <bits/stdc++.h>
using namespace std;
template <typename T, typename D>
std::ostream& operator<<(std::ostream& os, const std::pair<T, D>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a;
  a.push_back(0);
  for (int i = (0); i < (n); i++) {
    long long e;
    cin >> e;
    a.push_back(e);
  }
  a.push_back(1001);
  long long max_chain = 1;
  long long curr_num = 0;
  long long chain = 1;
  for (int i = (1); i < (n + 2); i++) {
    if (a[i] == curr_num + 1) {
      chain++;
      if (chain > max_chain) max_chain = chain;
    } else {
      chain = 1;
    }
    curr_num = a[i];
  }
  cout << max(max_chain - 2, 0ll) << "\n";
}
