#include <bits/stdc++.h>
using namespace std;
long long b[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i, j, z, y = 0, count = 0, sum = 0, n, m;
  cin >> n;
  long long a[n];
  vector<long long> v;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  set<long long> s;
  while (y < v.size()) {
    b[v[y]] = y;
    s.insert(v[y]);
    if (s.size() <= 2) {
      sum = max(sum, y + 1);
    } else {
      auto it2 = s.find(v[y]);
      s.erase(it2);
      auto it = s.begin();
      auto it1 = s.end();
      it1--;
      if (abs(v[y] - *it) > 1) {
        v.erase(v.begin(), v.begin() + b[*it] + 1);
      } else if (abs(v[y] - *it1) > 1) {
        v.erase(v.begin(), v.begin() + b[*it1] + 1);
      }
      count = 1;
      y = 0;
      s.clear();
    }
    if (count == 1)
      count = 0;
    else
      y++;
  }
  cout << sum << endl;
  return 0;
}
