#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, a[maxn], lst[maxn], maxL, ans;
inline int read() {
  int ret = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - 48, ch = getchar();
  return ret;
}
int main() {
  memset(lst, -1, sizeof lst);
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) {
    int x = -1;
    if (a[i] <= 99998) x = max(x, lst[a[i] + 2]);
    if (a[i] >= 2) x = max(x, lst[a[i] - 2]);
    maxL = max(maxL, x);
    ans = max(ans, i - maxL);
    lst[a[i]] = i;
  }
  printf("%d\n", ans);
  return 0;
}
