#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
const int N = 300005;
int n, k;
int a[N];
int d[N];
int t[2 * N];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[tl] = a[v];
  } else {
    int tm = (tl + tr) >> 1;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    t[v] = max(t[2 * v], t[2 * v + 1]);
  }
}
void build() { build(0, 0, n - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int mn = inf;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mn = min(mn, a[i]);
  }
  d[0] = mn;
  for (int i = 1; i <= n; i++) d[i] = inf;
  for (int i = 1; i < n; i++) {
    int j = int(upper_bound(d, d + n, a[i]) - d);
    if (abs(d[j - 1] - a[i]) <= k && a[i] < d[j]) {
      d[j] = a[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] != inf) ans = d[i];
  }
  cout << ans << endl;
  return 0;
}
