#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long int;
int n, k;
const int maxN = 300000;
int a[maxN];
int ans;
void solve(int x, int last, int steps) {
  if (x >= n) {
    ans = max(ans, steps);
    return;
  }
  if (last != -1 && abs(a[last] - a[x]) != k) return;
  for (int i = x + 1; i < n; i++) {
    solve(i, x, steps + 1);
  }
  ans = max(ans, steps);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = 0;
  for (int i = 0; i < n; i++) {
    solve(i, -1, 1);
  }
  cout << ans;
}
