#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
const long long MOD = 1000000007;
long long sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
  return a + sum(args...);
}
void solve(vector<int>& a, int k) {
  int ans = 0, n = a.size();
  vector<int> dp(n, 0);
  int cnt[26] = {0};
  for (int(i) = (0); (i) < (n); ++(i)) {
    int mi = max(0, a[i] - k);
    int mx = min(25, a[i] + k);
    for (int(j) = (mi); (j) < (mx + 1); ++(j)) dp[i] = max(dp[i], cnt[j] + 1);
    cnt[a[i]] = max(cnt[a[i]], dp[i]);
  }
  for (auto&(x) : (dp)) ans = max(ans, x);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int x;
  for (int(i) = (0); (i) < (n); ++(i)) {
    cin >> x;
    a[i] = x % 26;
  }
  solve(a, k);
  return 0;
}
