#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> dp(n, 1);
  vector<int> bak(n + 3, 0);
  bak[a[0]] = 1;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int maxd = 0;
    if (a[i] - 3 >= 1) maxd = max(maxd, bak[a[i] - 3]);
    if (a[i] - 2 >= 1) maxd = max(maxd, bak[a[i] - 2]);
    if (a[i] - 1 >= 1) maxd = max(maxd, bak[a[i] - 1]);
    maxd = max(maxd, bak[a[i]]);
    maxd = max(maxd, bak[a[i] + 1]);
    maxd = max(maxd, bak[a[i] + 2]);
    maxd = max(maxd, bak[a[i] + 3]);
    dp[i] += maxd;
    chmax(bak[dp[i]], dp[i]);
    chmax(ans, dp[i]);
  }
  cout << ans;
}
