#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 10;
int n, ans = 1;
int a[MAX_N], b[MAX_N], c[MAX_N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      b[i] = i - 1;
      c[i] = c[c[i - 1]];
    }
    if (a[i] > a[i - 1]) {
      b[i] = b[b[i - 1]];
      c[i] = i - 1;
    }
    if (a[i] == a[i - 1]) {
      b[i] = b[i - 1];
      c[i] = c[i - 1];
    }
  }
  for (int i = 2; i <= n; i++) {
    int an = (i - (max(b[b[i]], c[i]) + 1)) + 1;
    an = max(an, (i - (max(b[i], c[c[i]]) + 1)) + 1);
    ans = max(ans, an);
  }
  cout << ans << endl;
}
