#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} debug;
int n;
int main() {
  do {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  } while (0);
  int n, tmp;
  vector<int> a;
  cin >> n;
  while (cin >> tmp) {
    a.emplace_back(tmp);
  }
  int i = 1, j = 0, k = 0, max_d = 0;
  int valid[3] = {0, a[0], 0};
  for (; i < n; ++i) {
    if (a[i] == valid[1]) continue;
    if ((a[i] == (valid[1] + 1)) && !valid[0]) {
      valid[2] = a[i];
      continue;
    }
    if ((a[i] == (valid[1] - 1)) && !valid[2]) {
      valid[0] = a[i];
      continue;
    }
    max_d = max(max_d, i - j);
    j = i - 1;
    while (abs(a[i] - a[j]) <= 1) {
      --j;
    }
    ++j;
    valid[0] = (a[i] == a[j] - 1) ? a[i] : 0;
    valid[1] = a[j];
    valid[2] = (a[i] == a[j] + 1) ? a[i] : 0;
  }
  max_d = max(max_d, i - j);
  cout << max_d << endl;
  return 0;
}
