#include <bits/stdc++.h>
using namespace std;
int s[10005], dp[10005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    for (int j = 1; j < i; j++) {
      if (abs(s[i] - s[j]) <= 3) dp[i] = max(dp[i], dp[j] + 1);
    }
  }
  int maxi = -1;
  for (int i = 1; i <= n; i++) maxi = max(maxi, dp[i]);
  cout << maxi << endl;
  return 0;
}
