#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, num[N], Q1[N], Q2[N], Q3[N];
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
    int l1 = 0, r1 = -1;
    int l2 = 0, r2 = -1;
    int l3 = 0, r3 = -1;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      Q1[++r1] = i;
      while (r2 >= l2 && num[Q2[r2]] > num[i]) r2--;
      Q2[++r2] = i;
      while (r3 >= l3 && num[Q3[r3]] < num[i]) r3--;
      Q3[++r3] = i;
      while (num[Q3[l3]] - num[Q2[l2]] > 1) {
        if (Q1[l1] == Q2[l2]) l2++;
        if (Q1[l1] == Q3[l3]) l3++;
        l1++;
      }
      ans = max(ans, i - Q1[l1] + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
