#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int prev = -1;
  int next, current;
  int prevCount = 0;
  int currentCount = 1;
  int longest = 1;
  cin >> current;
  for (int i = 1; i < n; i++) {
    cin >> next;
    if (next == current) {
      currentCount++;
    } else if (next == prev) {
      prevCount += currentCount;
      prev = current;
      current = next;
      currentCount = 1;
    } else {
      longest = max(longest, prevCount + currentCount);
      prev = current;
      prevCount = currentCount;
      current = next;
      currentCount = 1;
    }
  }
  cout << max(longest, currentCount + prevCount) << endl;
}
