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