#include <bits/stdc++.h>
int scan() {
  int noRead = 0;
  char p = getchar();
  for (; p < 33;) {
    p = getchar();
  }
  while (p > 32) {
    noRead = (noRead << 3) + (noRead << 1) + (p - '0');
    p = getchar();
  }
  return noRead;
}
using namespace std;
vector<int> vec[100010];
vector<int> v[100010];
int a[100010];
int main(void) {
  ios_base::sync_with_stdio(false);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    vec[a[i]].push_back(i);
  }
  int ans = 1;
  for (int i = 0; i < 100005; ++i) {
    int sza = vec[i].size();
    for (int j = 0; j < sza; ++j) v[i].push_back(vec[i][j]);
    int szb = vec[i + 1].size();
    for (int j = 0; j < szb; ++j) v[i].push_back(vec[i + 1][j]);
    sort(v[i].begin(), v[i].end());
    int currmax = 1;
    int szv = v[i].size();
    for (int j = 1; j < szv; ++j) {
      int curr = 1;
      while ((j < szv) &&
             ((v[i][j] == v[i][j - 1]) || (v[i][j] == v[i][j - 1] + 1))) {
        curr++;
        j++;
      }
      currmax = max(currmax, curr);
    }
    ans = max(ans, currmax);
  }
  printf("%d", ans);
  return 0;
}
