#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(vector<T> &v) {
  for (int i = 0; i < (int)v.size(); ++i) cout << v[i] << " ";
  cout << endl;
}
int nxt() {
  int x;
  cin >> x;
  return x;
}
long long nxtl() {
  long long x;
  cin >> x;
  return x;
}
string nxts() {
  string x;
  cin >> x;
  return x;
}
double nxtd() {
  double x;
  cin >> x;
  return x;
}
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long power_mod(long long a, long long b, long long mo) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans % mo * a % mo) % mo;
    }
    a = (a % mo * a % mo) % mo;
    b /= 2;
  }
  return ans;
}
long long POW(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a;
    }
    a = a * a;
    b /= 2;
  }
  return ans;
}
int const p = 300000;
int dp[p + 1];
int v[p + 1];
int segment_tree[2 * p + 2];
int n, k;
int sized = p;
int query(int l_in, int r_in, int index = 1, int l = 1, int r = sized) {
  if (r_in >= r && l_in <= l) {
    return segment_tree[index];
  }
  if (l_in > r || r_in < l) {
    return 0;
  }
  int mid = (l + r) / 2;
  return max(query(l_in, r_in, index * 2, l, mid),
             query(l_in, r_in, index * 2 + 1, mid + 1, r));
}
void update(int index_in, int val, int index = 1, int l = 1, int r = sized) {
  if (l == r) {
    segment_tree[index] = val;
    return;
  }
  int mid = (l + r) / 2;
  if (index_in <= mid) {
    update(index_in, val, index * 2, l, mid);
  } else {
    update(index_in, val, index * 2 + 1, mid + 1, r);
  }
  segment_tree[index] =
      max(segment_tree[index * 2], segment_tree[index * 2 + 1]);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    v[i]++;
  }
  for (int i = n - 1; i >= 0; --i) {
    int r = (v[i] + k >= p) ? p : v[i] + k;
    int l = (v[i] - k >= 1) ? v[i] - k : 1;
    int val = query(l, r);
    dp[v[i]] = val + 1;
    update(v[i], dp[v[i]]);
  }
  int maxm = 0;
  for (int i = 0; i <= p; ++i) maxm = max(maxm, dp[i]);
  cout << maxm;
}
