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