#include <bits/stdc++.h>
using namespace std;
int *A, *S, m = 0;
void search(int i, int cnt, int n) {
  int p = A[i];
  cnt++;
  S[i] = cnt;
  m = max(m, cnt);
  for (int k = i + 1; k < n; k++) {
    if (abs(p - A[k]) <= 3) {
      if (S[k] > cnt) continue;
      search(k, cnt, n);
    }
  }
}
int main() {
  long long int n, k;
  cin >> n >> k;
  A = new int[n];
  S = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    S[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    if (S[i] == 0) search(i, 0, n);
  }
  cout << m << endl;
  return 0;
}
