#include <bits/stdc++.h>
using namespace std;
int seq[100005], n;
int last[100005];
int func() {
  for (int i = 0; i < 100005; ++i) last[i] = -1;
  int ans = 1, maxi = seq[0], mini = seq[0];
  int counter = 1;
  last[seq[0]] = 0;
  for (int i = 1; i < n; ++i) {
    maxi = max(maxi, seq[i]);
    mini = min(mini, seq[i]);
    if (maxi - mini <= 1) {
      counter++;
    } else {
      int curLast = last[maxi - 2];
      if (seq[i] == maxi) {
        counter = i - curLast;
        mini++;
      } else {
        curLast = last[maxi];
        counter = i - curLast;
        maxi--;
      }
    }
    last[seq[i]] = i;
    ans = max(ans, counter);
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> seq[i];
  }
  int ans = func();
  reverse(seq, seq + n);
  ans = max(ans, func());
  cout << ans << endl;
  return 0;
}
