#include <bits/stdc++.h>
using namespace std;
int getMid(int s, int e) { return s + (e - s) / 2; }
int MaxUtil(int* st, int ss, int se, int l, int r, int node) {
  if (l <= ss && r >= se) return st[node];
  if (se < l || ss > r) return -1;
  int mid = getMid(ss, se);
  return max(MaxUtil(st, ss, mid, l, r, 2 * node + 1),
             MaxUtil(st, mid + 1, se, l, r, 2 * node + 2));
}
void updateValue(int arr[], int* st, int ss, int se, int index, int value,
                 int node) {
  if (index < ss || index > se) {
    cout << "Invalid Input" << endl;
    return;
  }
  if (ss == se) {
    arr[index] = value;
    st[node] = value;
  } else {
    int mid = getMid(ss, se);
    if (index >= ss && index <= mid)
      updateValue(arr, st, ss, mid, index, value, 2 * node + 1);
    else
      updateValue(arr, st, mid + 1, se, index, value, 2 * node + 2);
    st[node] = max(st[2 * node + 1], st[2 * node + 2]);
  }
  return;
}
int getMax(int* st, int n, int l, int r) {
  if (l < 0 || r > n - 1 || l > r) {
    printf("Invalid Input");
    return -1;
  }
  return MaxUtil(st, 0, n - 1, l, r, 0);
}
int constructSTUtil(int arr[], int ss, int se, int* st, int si) {
  if (ss == se) {
    st[si] = arr[ss];
    return arr[ss];
  }
  int mid = getMid(ss, se);
  st[si] = max(constructSTUtil(arr, ss, mid, st, si * 2 + 1),
               constructSTUtil(arr, mid + 1, se, st, si * 2 + 2));
  return st[si];
}
int* constructST(int arr[], int n) {
  int x = (int)(ceil(log2(n)));
  int max_size = 2 * (int)pow(2, x) - 1;
  int* st = new int[max_size];
  constructSTUtil(arr, 0, n - 1, st, 0);
  return st;
}
void solve() {
  int n, k;
  cin >> n >> k;
  int s[300005] = {};
  int* st = constructST(s, 2 * n + 2);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    int lastMax = getMax(st, 2 * n + 2, max(1, a - k), min(n, a + k));
    updateValue(s, st, 0, 2 * n + 1, a, lastMax + 1, 0);
  }
  cout << getMax(st, 2 * n + 2, 1, n) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
