#include <bits/stdc++.h>
using namespace std;
int n;
int dp[100005][20];
int dp1[100005][20];
int a[100005];
int L[100005], R[100005];
int mm[100005];
void initrmp(int n) {
  mm[0] = -1;
  for (int i = 1; i <= n; i++) {
    mm[i] = ((i & (i - 1)) == 0) ? mm[i - 1] + 1 : mm[i - 1];
    dp[i][0] = a[i];
    dp1[i][0] = a[i];
  }
  for (int j = 1; j <= mm[n]; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
  for (int j = 1; j <= mm[n]; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      dp1[i][j] = min(dp1[i][j - 1], dp1[i + (1 << (j - 1))][j - 1]);
}
int queryMax(int l, int r) {
  int k = mm[r - l + 1];
  return max(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int queryMin(int l, int r) {
  int k = mm[r - l + 1];
  return min(dp1[l][k], dp1[r - (1 << k) + 1][k]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int Ans = 0;
  initrmp(n);
  for (int i = 1; i <= n; i++) {
    int l = 1, r = i;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (abs(a[i] - queryMin(mid, i)) <= 0 &&
          abs(a[i] - queryMax(mid, i)) <= 1)
        r = mid - 1;
      else
        l = mid + 1;
    }
    L[i] = l;
    l = i, r = n;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (abs(a[i] - queryMin(i, mid)) <= 0 &&
          abs(a[i] - queryMax(i, mid)) <= 1)
        l = mid + 1;
      else
        r = mid - 1;
    }
    R[i] = l - 1;
  }
  for (int i = 1; i <= n; i++) Ans = max(Ans, R[i] - L[i] + 1);
  for (int i = 1; i <= n; i++) {
    int l = 1, r = i;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (abs(a[i] - queryMin(mid, i)) <= 1 &&
          abs(a[i] - queryMax(mid, i)) <= 0)
        r = mid - 1;
      else
        l = mid + 1;
    }
    L[i] = l;
    l = i, r = n;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (abs(a[i] - queryMin(i, mid)) <= 1 &&
          abs(a[i] - queryMax(i, mid)) <= 0)
        l = mid + 1;
      else
        r = mid - 1;
    }
    R[i] = l - 1;
  }
  for (int i = 1; i <= n; i++) Ans = max(Ans, R[i] - L[i] + 1);
  cout << Ans << endl;
}
