#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <typename T>
struct RMQ {
  const T INF = 0;
  int n;
  vector<T> dat, lazy;
  function<T(T, T)> fx = [](T x1, T x2) -> T { return max(x1, x2); };
  RMQ(int n_) : n(), dat(n_ * 4, INF), lazy(n_ * 4, INF) {
    int x = 1;
    while (n_ > x) x *= 2;
    n = x;
  }
  void set(int i, T x) { dat[i + n - 1] = x; }
  void build() {
    for (int k = n - 2; k >= 0; k--)
      dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
  }
  void eval(int k) {
    if (lazy[k] == INF) return;
    if (k < n - 1) {
      lazy[k * 2 + 1] = lazy[k];
      lazy[k * 2 + 2] = lazy[k];
    }
    dat[k] = lazy[k];
    lazy[k] = INF;
  }
  void update(int a, int b, T x, int k, int l, int r) {
    eval(k);
    if (a <= l && r <= b) {
      lazy[k] = x;
      eval(k);
    } else if (a < r && l < b) {
      update(a, b, x, k * 2 + 1, l, (l + r) / 2);
      update(a, b, x, k * 2 + 2, (l + r) / 2, r);
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
  T query_sub(int a, int b, int k, int l, int r) {
    eval(k);
    if (r <= a || b <= l) {
      return INF;
    } else if (a <= l && r <= b) {
      return dat[k];
    } else {
      T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }
  T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
  T find_rightest(int a, int b, int x) {
    return find_nearest_sub(a, b, x, 0, 0, n, true);
  }
  T find_leftest(int a, int b, int x) {
    return find_nearest_sub(a, b, x, 0, 0, n, false);
  }
  T find_nearest_sub(int a, int b, int x, int k, int l, int r, bool is_right) {
    eval(k);
    if (dat[k] > x || r <= a || b <= l) {
      return -1;
    } else if (k >= n - 1) {
      return (k - (n - 1));
    } else {
      if (is_right) {
        int vr = find_nearest_sub(a, b, x, 2 * k + 2, (l + r) / 2, r, is_right);
        if (vr != -1) {
          return vr;
        } else {
          return find_nearest_sub(a, b, x, 2 * k + 1, l, (l + r) / 2, is_right);
        }
      } else {
        int vl = find_nearest_sub(a, b, x, 2 * k + 1, l, (l + r) / 2, is_right);
        if (vl != -1) {
          return vl;
        } else {
          return find_nearest_sub(a, b, x, 2 * k + 2, (l + r) / 2, r, is_right);
        }
      }
    }
  }
};
int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  RMQ<int> seg(300010);
  for (ll i = ll(0); i < ll(n); i++) {
    int a;
    cin >> a;
    int l = max(0LL, a - m);
    int r = min(300000LL, a + m);
    seg.update(l, r + 1, a);
  }
  cout << seg.query(0, n);
}
