#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int main() {
  int n, k;
  cin >> n >> k;
  Graph g(n);
  vector<int> val(n);
  for (int i = 0; i < (n); i++) {
    cin >> val[i];
  }
  for (int i = 0; i < (n); i++) {
    for (int j = i + 1; j < n; j++) {
      if (abs(val[i] - val[j]) <= 3) g[i].push_back(j);
    }
  }
  int t = 0;
  int ans = 0;
  while (n - t >= ans) {
    vector<int> dist(n, -1);
    queue<int> que;
    dist[t] = 0;
    que.push(t);
    int dmax = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int nv : g[v]) {
        if (dist[nv] != -1) continue;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
    for (int i = 0; i < (n); i++) dmax = max(dmax, dist[i]);
    ans = max(dmax, ans);
  }
  cout << ans << endl;
  return 0;
}
