//FIRST THINK THEN CODE.

#include <bits/stdc++.h>


using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}



/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}



ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}




ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}


string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}


const ll N = 3e5 + 5;

struct segtree {

  vl nums;

  ll size;

  void ini(ll n) {
    size = 1;
    while (size < n) {
      size *= 2;
    }
    nums.assign(2 * size, 0);
  }

  void update(ll x, ll lx, ll rx, ll idx, ll delta) {
    if (rx - lx == 1) {
      nums[x] = delta;
      return;
    }
    ll m = (lx + rx) / 2;
    if (idx < m)
      update(2 * x + 1, lx, m, idx, delta);
    else update(2 * x + 2, m, rx, idx, delta);

    nums[x] = nums[2 * x + 1] + nums[2 * x + 2];

  }

  void update(ll idx, ll delta) {
    update(0, 0, size, idx, delta);
  }

  ll calc(ll x, ll lx, ll rx, ll l, ll r) {
    if (lx >= r || rx <= l)return 0;

    if (lx >= l && rx <= r)return nums[x];

    ll m = (lx + rx) / 2;

    return calc(2 * x + 1, lx, m, l, r) + calc(2 * x + 2, m, rx, l, r);
  }

  ll calc(ll l, ll r) {
    return calc(0, 0, size, l, r);
  }

  void build(ll x, ll lx, ll rx, vl& a) {
    if (rx - lx == 1) {
      if (lx < a.size())nums[x] = a[lx];
      return;
    }

    ll m = (lx + rx) / 2;

    build(2 * x + 1, lx, m, a);
    build(2 * x + 2, m, rx, a);

    nums[x] = nums[2 * x + 1] + nums[2 * x + 2];

  }

  void build(vl& a) {
    build(0, 0, size, a);
  }

  /*
    "add" mass operation in which element 'v' being added to the segment
      [l,r-1].
  */

  void add(ll x, ll lx, ll rx, ll l, ll r, ll v) {
    if (lx >= r || rx <= l)return;
    if (lx >= l && rx <= r) {
      nums[x] = max(nums[x], v);
      return ;
    }
    ll m = (lx + rx) / 2;
    add(2 * x + 1, lx, m, l, r, v);
    add(2 * x + 2, m, rx, l, r, v);
  }

  void add(ll l, ll r, ll  v) {
    add(0, 0, size, l, r, v);
  }


// gives the value at index 'idx'.
  ll get(ll x, ll lx, ll rx, ll idx) {
    if (rx - lx == 1) {
      return nums[x];
    }
    ll m = (lx + rx) / 2;
    ll temp;
    if (idx < m) {
      temp = get(2 * x + 1, lx, m, idx);
    } else {
      temp = get(2 * x + 2, m, rx, idx);
    }
    return max(temp,nums[x]);
  }

  ll get(ll idx) {
    return get(0, 0, size, idx);
  }

};



int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif




  ll n, k;

  cin >> n >> k;


  segtree sg;

  sg.ini(N);

  ll ans = 0;

  FOR(i, n) {
    ll x; cin >> x;
    ll left = max(0ll, x - k);
    ll right = min(N, x + k + 1);

    ll y = sg.get(x);

    sg.add(left, right, y + 1);

    ans = max(ans, y + 1);

  }

  cout << ans;


  return 0;
}

Measured memory_bytes: 11416