#include <bits/stdc++.h>
using namespace std;
long long a[200000], us[200000];
int main() {
  ios_base::sync_with_stdio(0);
  long long n, l, i, mx = -1, j, ans = 0;
  cin >> n;
  l = 1;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    mx = a[i];
    us[a[i]]++;
    if (mx - 2 >= 0 && us[mx - 2] > 0 || us[mx + 2] > 0) {
      for (j = l; j <= i; j++) {
        us[a[j]]--;
        if (us[mx - 2] == 0 && us[mx + 2] == 0) l = j + 1, j = i + 1;
      }
    }
    ans = max(ans, i - l + 1);
  }
  cout << ans;
}
