#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
int A[300001];
int diff[300001];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> A[i];
  vector<vector<int>> adj(N + 1);
  A[0] = -1;
  for (int i = 1; i <= N; i++) {
    if (A[i] == A[i - 1]) continue;
    for (int j = i + 1; j <= N; j++) {
      if (A[j] == A[i]) {
        adj[i].push_back(j);
        break;
      }
    }
    for (int j = i + 1; j <= N; j++) {
      if (A[j] > A[i] && A[j] - A[i] <= K) {
        adj[i].push_back(j);
        break;
      }
    }
    for (int j = i + 1; j <= N; j++) {
      if (A[j] < A[i] && A[i] - A[j] <= K) {
        adj[i].push_back(j);
        break;
      }
    }
  }
  queue<pair<int, int>> q;
  q.push({1, 1});
  int ans = 0;
  while (!q.empty()) {
    int now = q.front().first;
    int cnt = q.front().second;
    ans = max(ans, cnt);
    q.pop();
    for (int next : adj[now]) {
      q.push({next, cnt + 1});
    }
  }
  cout << ans;
}
