#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
struct Seq;
struct Seq {
  Seq(const VI* inputStream) : stream(inputStream) { start = end = -1; }
  bool valid() const { return end > start; }
  int getCc() const {
    int len = end - start;
    int res = len - 2;
    if ((*stream)[start] == 1) res++;
    if ((*stream)[end - 1] == 1000) res++;
    return res;
  }
  void setStart(int inpStart) { start = inpStart; }
  void setEnd(int inpEnd) { end = inpEnd; }
  void printSeq() const {
    if (!valid()) {
      cout << "Seq is invalid\n";
      return;
    }
    cout << "{";
    for (int i = start; i < end; i++) {
      cout << (*stream)[i] << ",";
    }
    cout << "} startPos=" << start << ", end=" << end << ", len=" << getCc()
         << "\n";
  }

 private:
  int start;
  int end;
  const VI* stream;
};
struct StreamConsumer {
  StreamConsumer(const VI& inputStream) : stream(inputStream) { pos = 0; }
  Seq getNextSeq() {
    Seq seq(&stream);
    if (pos >= stream.size()) return seq;
    seq.setStart(pos);
    while (pos + 1 < stream.size() && (stream[pos + 1] - stream[pos]) == 1) {
      pos++;
    }
    pos++;
    seq.setEnd(pos);
    return seq;
  }
  const VI& stream;
  int pos;
};
VI getStream() {
  int n;
  cin >> n;
  VI stream;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    stream.push_back(t);
  }
  return stream;
}
VI getStaticStream() {
  VI stream{1, 2, 4, 5, 6, 7, 8, 9, 12};
  return stream;
}
int main() {
  int res = 0;
  VI stream = getStream();
  StreamConsumer streamConsumer(stream);
  Seq seq = streamConsumer.getNextSeq();
  while (seq.valid()) {
    res = max(res, seq.getCc());
    seq = streamConsumer.getNextSeq();
  }
  cout << res;
  return 0;
}
