#include <bits/stdc++.h>
using namespace std;
int n, a[100005] = {0}, ans;
int main() {
  int i, j, k, h;
  scanf("%d", &n);
  ans = 1, h = 1;
  scanf("%d", &j);
  a[j] = 1;
  for (i = 2; i <= n; i++) {
    scanf("%d", &k);
    if (k == j)
      h++;
    else if (k == j + 1)
      h = min(i - a[k - 2], h + 1);
    else if (k == j - 1)
      h = min(i - a[k + 2], h + 1);
    a[k] = i;
    j = k;
    ans = max(ans, h);
  }
  printf("%d\n", ans);
  return 0;
}
