#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr;
int main() {
  cin >> n;
  arr.resize(n + 1);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int maxi = arr[1], mini = arr[1], miniocc = 1, maxiocc = 1, i1 = 1, i2 = 1,
      ans = 1;
  for (int i = 2; i <= n; i++) {
    int c = 0;
    if (arr[i] <= mini) {
      mini = arr[i];
      miniocc = i;
      i2++;
      c = 1;
    }
    if (arr[i] >= maxi) {
      maxi = arr[i];
      maxiocc = i;
      if (c == 0) i2++;
    }
    if (abs(maxi - mini) > 1) {
      if (arr[i] == maxi) {
        i1 = miniocc + 1;
        miniocc = maxiocc - 1;
        mini += 1;
      }
      if (arr[i] == mini) {
        i1 = maxiocc + 1;
        maxiocc = miniocc - 1;
        maxi = maxi - 1;
      }
    }
    ans = max(ans, i2 - i1 + 1);
  }
  cout << ans;
}
