#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 300100;

class MaxsegmentTree{
  public:
    vector<ll> segment;
    MaxsegmentTree(){}
    MaxsegmentTree(ll ssize){
       for(ll i = 0; i < 4LL * ssize + 1LL; i++){
           segment.push_back(0LL);
       }
    }

    ll query(ll l, ll r, ll start, ll end, ll node){
        if(r < start || l > end) return -INF;
        if(start <= l && end >= r) return segment[node];
        ll mid = (l + r) >> 1;
        ll left = query(l, mid, start, end, node + node);
        ll right = query(mid + 1, r, start, end, node + node + 1);
        return max(left, right);
    }

    void update(ll l, ll r, ll index, ll val, ll node){
        if(l == r){
            segment[node] = val;
            return;
        }
        ll mid = (l + r) >> 1;
        if(l <= index && index <= mid) update(l, mid, index, val, node + node);
        else update(mid + 1, r, index, val, node + node + 1);
        segment[node] = max(segment[node + node], segment[node + node + 1]);
    }
};

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int TestCases = 1; // cin >> TestCases;
    while(TestCases--){
       int n,k; cin >> n >> k;
       std::vector<int> a(n + 1);
       for(int i = 1; i <= n; i++){
          cin >> a[i];
          a[i] += 1;
      }
       MaxsegmentTree b(maxn);
       int ans = 1;
       for(int i = 1; i <= n; i++){
          int l = max(1, a[i] - k);
          int r = min(maxn - 1, a[i] + k);
          int val = b.query(1, maxn - 1, l, r, 1);
          ans = max(ans, 1 + val);
          b.update(1, maxn - 1, a[i], 1 + val, 1);
       }
       cout << ans << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 20880