#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> cnt(1e5 + 5);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    cnt[num]++, cnt[num + 1]++;
    ans = max(ans, max(cnt[num], cnt[num + 1]));
    cnt[num - 1] = 0, cnt[num + 2] = 0;
  }
  cout << ans;
  return 0;
}
