#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.first << ' ' << p.second << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9+10;
//const int mod=1000000007;
const int mod=998244353;

int n,m,k;
const int N=3e5+10;

struct segtree {
    struct node{
        long long int min,max,sum;
    };
    vector<node> st;
    int n;
    template<typename M>
    segtree(M size){
        n=size+10;
        st.resize(4*n);
    }
    
    template<typename M>
    segtree(vector<M> &a){
        n=(int)a.size();
        st.resize(4*n);
        build(1, 0, n-1, a);
    }
    
    void combine(node &a,node &b,node &c){
        a.sum=b.sum+c.sum;
        a.min=min(b.min, c.min);
        a.max=max(b.max,c.max);
    }
    template <typename M>
    void build(int v,int l,int r, vector<M> &vec){
        if (l==r) {
            st[v].max=vec[l];
            st[v].min=vec[l];
            st[v].sum=vec[l];
        }
        else{
            int m=(l+r)/2;
            build(2*v, l, m ,vec);
            build(2*v+1, m+1, r , vec);
            combine(st[v], st[2*v], st[2*v+1]);
        }
    }
    node query(int v,int l,int r,int l_,int r_){
        if (l==l_&&r==r_) {
            return st[v];
        }
        int m=(l+r)/2;
        if (r_<=m) {
            return query(2*v, l, m, l_, r_);
        }
        else if (l_>m){
            return query(2*v+1, m+1, r, l_, r_);
        }
        else{
            node a,b,c;
            b=query(2*v, l, m, l_, m);
            c=query(2*v+1, m+1, r, m+1, r_);
            combine(a, b, c);
            return a;
        }
    }
    template <typename M>
    void update(int v,int l,int r,int id,M val){
        if (l==r) {
            st[v].min=val;
            st[v].max=val;
            st[v].sum=val;
            return;
        }
        int m=(l+r)/2;
        if (id<=m) {
            update(2*v, l, m, id, val);
        } else {
            update(2*v+1, m+1, r, id, val);
        }
        combine(st[v], st[2*v], st[2*v+1]);
    }
    long long int query(int l,int r){
        return query(1, 0, n-1, l, r).max;
    }
    template <typename M>
    void update(int id, M val){
        update(1, 0, n-1, id, val);
    }
    
};

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    segtree st(N);
    for(int i=0, u, l, r, t; i<n; i++){
        cin >> u;
        l=u-k; r=u+k;
        l=max(l,0); r=min(r,N);
        t=(int)st.query(l,r);
        st.update(u,t+1);
    }
    cout << st.query(0,N) << el;
    
    
    return 0;
}








Measured memory_bytes: 31456