#include <bits/stdc++.h>
using namespace std;
const int A = 1e5 + 5;
int arr[A];
int main() {
  int n;
  cin >> n;
  int l = 0, x;
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    x++;
    l = max(l, arr[x - 2]);
    l = max(l, arr[x + 2]);
    arr[x] = i;
    ans = max(ans, i - l);
  }
  cout << ans << endl;
  return 0;
}
