#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int v[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", v + i);
  }
  multiset<int> set;
  int l = 0, r = 0;
  int ret = 0;
  int a;
  int m, M;
  while (l < n) {
    while (r < n) {
      if (set.empty()) {
        set.emplace(v[r++]);
        continue;
      }
      m = *set.begin();
      M = *set.rbegin();
      a = v[r];
      if (a >= M && abs(a - m) <= 1) {
        set.emplace(a);
        r++;
      } else if (a <= m && abs(a - M) <= 1) {
        set.emplace(a);
        r++;
      } else {
        break;
      }
    }
    ret = max(ret, r - l);
    if (l == r) {
      l++;
      r++;
      continue;
    }
    while (l < r) {
      m = *set.begin();
      M = *set.rbegin();
      set.erase(set.find(v[l++]));
      if (set.empty() || *set.begin() > m || *set.rbegin() < M) {
        break;
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}
