#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using ld = long double;
using ll = long long;
using VI = vector<long long>;
using VVI = vector<vector<long long>>;
using VVC = vector<vector<char>>;
template <class T>
using PQ_inv = priority_queue<T, vector<T>, greater<T>>;
const double pai = 3.1415926535897;
const long long INF = 1000000021;
const ll LINF = 2000000000000000000;
const ll mod = 1000000007;
const long long MAX = 2010000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
struct edge {
  long long to, cost;
};
edge m_e(long long xx, long long yy) {
  edge ed;
  ed.to = xx;
  ed.cost = yy;
  return ed;
}
const auto identify_element = 0;
template <class T>
T op(T xx, T yy) {
  return max(xx, yy);
}
template <class T>
class segment_tree {
  long long root_size;
  vector<T> data;

 public:
  segment_tree(vector<T> v) {
    long long a = 0;
    while (v.size() > (1ll << a)) a++;
    root_size = 1ll << a;
    data.resize((root_size << 1) - 1, identify_element);
    for (long long i = 0; i < (long long)(v.size()); i++) {
      data[i + root_size - 1] = v[i];
    }
    for (long long i = root_size - 2; i >= 0; i--) {
      data[i] = op(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  segment_tree(long long xx) {
    long long a = 0;
    while (xx > (1ll << a)) a++;
    root_size = 1ll << a;
    data.resize((root_size << 1) - 1, identify_element);
    for (long long i = 0; i < (long long)(xx); i++) {
      data[i + root_size - 1] = 0;
    }
    for (long long i = root_size - 2; i >= 0; i--) {
      data[i] = op(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  void update(long long p, T xx) {
    long long a = p + root_size - 1;
    data[a] = xx;
    while (a != 0) {
      a = (a - 1) / 2;
      data[a] = op(data[a * 2 + 2], data[a * 2 + 1]);
    }
  }
  T get(long long xx) { return data[root_size + xx - 1]; }
  T get_sum(long long l, long long r) {
    long long a = 1, p = l + root_size - 1;
    T ret = identify_element;
    bool bo = 1;
    while (r + 1 > l) {
      if (a > r - l + 1) {
        bo = 0;
        a >>= 1;
        p = p * 2 + 1;
        continue;
      }
      if (bo) {
        if (l & a) {
          ret = op(ret, data[p]);
          l += a;
          p++;
        }
        a <<= 1;
        p = (p - 1) / 2;
      } else {
        if (r - l + 1 & a) {
          ret = op(ret, data[p]);
          l += a;
          p++;
        }
        a >>= 1;
        p = p * 2 + 1;
      }
    }
    return ret;
  }
  T all() { return data[0]; }
  void debug() {
    for (long long i = root_size - 1; i < root_size * 2 - 1; i++) {
      cout << data[i] << " ";
    }
    cout << "\n";
  }
};
class BIT {
  vector<long long> data;

 public:
  ;
  BIT(vector<long long> v) {
    data.resize(v.size(), identify_element);
    for (long long i = 0; i < (long long)(v.size()); i++) {
      add(i, v[i]);
    }
  }
  void add(long long p, long long xx) {
    for (long long i = p + 1; i <= (long long)data.size(); i += (i & -i)) {
      data[i - 1] += xx;
    }
  }
  long long get_sum(long long r) {
    long long ret = identify_element;
    for (long long i = r + 1; i > 0; i -= (i & -i)) {
      ret += data[i - 1];
    }
    return ret;
  }
};
class union_find {
  VI union_size;

 public:
  ;
  VI table;
  union_find(long long xx) {
    table.resize(xx);
    for (long long i = 0; i < (long long)(xx); i++) table[i] = i;
    union_size.resize(xx, 1);
  }
  long long leader(long long xx) {
    if (table[xx] == xx) return xx;
    return table[xx] = leader(table[xx]);
  }
  void marge(long long xx, long long yy) {
    long long a = leader(xx), b = leader(yy);
    if (union_size[a] > union_size[b]) {
      table[b] = a;
      union_size[a] += union_size[b];
    } else {
      table[a] = b;
      union_size[b] += union_size[a];
    }
  }
  long long same(long long xx, long long yy) {
    if (leader(xx) == leader(yy))
      return true;
    else
      return false;
  }
  long long size(long long xx) { return union_size[leader(xx)]; }
};
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll PER(long long n, long long k) {
  if (n < 0 || k < 0) return 0;
  if (n < k) return fac[n];
  return fac[n] * finv[n - k] % mod;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long fix_mod(long long& xx) {
  if (xx >= mod * 2 || xx < -mod * 2) {
    xx %= mod;
  }
  if (xx >= mod) xx -= mod;
  return xx;
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
template <class T>
void vecout(vector<T>& vec) {
  for (T t : vec) cout << t << " ";
  cout << "\n";
}
template <class T>
void vecout(vector<vector<T>>& vec) {
  for (vector<T> tvec : vec) {
    for (T t : tvec) cout << t << " ";
    cout << "\n";
  }
}
template <class T>
void vecout(vector<pair<T, T>>& vec) {
  for (pair<T, T> p : vec) {
    cout << p.first << " " << p.second << "\n";
  }
}
template <class T>
void vecin(vector<T>& vec) {
  for (long long i = 0; i < (long long)vec.size(); i++) cin >> vec[i];
}
bool chmax(long long& xx, long long yy) {
  if (xx < yy) {
    xx = yy;
    return true;
  }
  return false;
}
bool chmin(long long& xx, long long yy) {
  if (xx > yy) {
    xx = yy;
    return true;
  }
  return false;
}
long long b_s(vector<long long>& vec, long long xx) {
  return lower_bound(vec.begin(), vec.end(), xx) - vec.begin();
}
long long gcd(long long xx, long long yy) {
  if (yy > xx) swap(xx, yy);
  while (xx % yy != 0) {
    xx %= yy;
    swap(xx, yy);
  }
  return yy;
}
long long lcm(long long xx, long long yy) { return (xx / gcd(xx, yy)) * yy; }
bool prime(long long xx) {
  if (xx <= 1) return 0;
  if (xx == 2) return 1;
  for (long long i = 3; i * i <= xx; i += 2) {
    if (xx % i == 0) {
      return 0;
    }
  }
  return 1;
}
signed main() {
  long long n, k;
  cin >> n >> k;
  VI vec(n);
  vecin(vec);
  segment_tree<long long> seg(300100);
  for (long long i = 0; i < (long long)(n); i++) {
    seg.update(vec[i], seg.get_sum(max(vec[i] - k, 0ll), vec[i] + k) + 1);
  }
  cout << seg.all() << "\n";
}
