#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long long powc(long long a, long long b) {
  if (b < 0) {
    return -1;
  }
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res *= a;
    }
    a *= a;
    b >>= 1;
  }
  return res;
}
void sw(char &c) {
  if (c == '1') {
    c = '0';
  } else {
    c = '1';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
  }
  long long ar[2];
  long long latest = 0;
  long long ans = 0;
  long long l = 0;
  for (long long i = 1; i < n; ++i) {
    if (v[i] - v[i - 1] != 0 && v[i] - v[i - 1] == latest) {
      if (latest == 1) {
        l = ar[0];
      } else {
        l = ar[1];
      }
    }
    if (v[i] - v[i - 1] != 0) {
      if (v[i] - v[i - 1] == 1) {
        latest = 1;
        ar[0] = i;
      } else {
        latest = -1;
        ar[1] = i;
      }
    }
    ans = max(ans, i - l + 1);
  }
  cout << ans;
}
