#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, cnt, ans, a[maxn], dp[maxn][20], fp[maxn][20];
void init_rmq() {
  for (int i = 1; i <= n; i++) dp[i][0] = fp[i][0] = a[i];
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      dp[j][i] = max(dp[j][i - 1], dp[j + (1 << i - 1)][i - 1]);
      fp[j][i] = min(fp[j][i - 1], fp[j + (1 << i - 1)][i - 1]);
    }
  }
}
int query_max(int l, int r) {
  int k = log2(r - l + 1);
  return max(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int query_min(int l, int r) {
  int k = log2(r - l + 1);
  return min(fp[l][k], fp[r - (1 << k) + 1][k]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  ans = 0;
  init_rmq();
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (query_max(j, i) - query_min(j, i) > 1 && j <= i) {
      j++;
    }
    ans = max(ans, i - j + 1);
  }
  cout << ans << endl;
  return 0;
}
