#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int a[N];
int dp[N];
int ans = 0;
int n, k;
void dfs(int x, int len) {
  if (len == n) return;
  ans = max(ans, dp[x]);
  for (int ad = 1; x + ad <= n; ++ad) {
    if (abs(a[x + ad] - a[x]) > 3) {
      if (dp[x + ad])
        ans = max(ans, dp[x + ad]);
      else
        dfs(x + ad, 1);
    } else {
      dp[x + ad] = len + 1;
      dfs(x + ad, len + 1);
      break;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  dp[1] = 1;
  dfs(1, 1);
  cout << ans;
}
