#include <bits/stdc++.h>
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  itval(++it, args...);
}
template <typename T>
inline void print(T x) {
  cout << x << "\n";
}
const long long int MOD = 1e9 + 7;
struct custom {
  bool operator()(const pair<int, int> &p1, const pair<int, int> &p2) const {
    if (p1.first == p2.first) {
      return p1.second > p2.second;
    }
    return p1.first < p2.first;
  }
};
long long int get_pow(long long int x, long long int k) {
  if (k == 0) return 1ll;
  long long int y = get_pow(x, k / 2);
  y = (y * y) % MOD;
  if (k % 2) y = (y * x) % MOD;
  return y;
}
const int N = 1e5 + 10;
void solve() {
  int n, x, ans = 0;
  cin >> n;
  map<int, int> m;
  for (int i = (int)0; i < int(n); i++) {
    cin >> x;
    m[x]++;
    m[x + 1]++;
    m[x - 1] = 0;
    m[x + 2] = 0;
    int z = max({m[x], m[x + 1]});
    ans = max(ans, z);
  }
  print(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  for (int tes = (int)0; tes < int(test); tes++) {
    solve();
  }
  return 0;
}
