#include <bits/stdc++.h>
using namespace std;

#include<atcoder/all>
using namespace atcoder;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

const int MAX_A = 300005;

int op(int a, int b) { return max(a,b);} 
int e() { return 0;}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, k) {
        cin >> a[i];
    }
    segtree<int, op, e> dp(MAX_A);
    rep(i, n) {
        int x = a[i];
        int l = x-k, r = x+k+1;
        l = max(l, 0);
        r = min(r, MAX_A);
        int now = dp.prod(l, r)+1;
        dp.set(x, now);
    }
    int ans = dp.prod(0, MAX_A);
    cout << ans << endl;
    return 0; 
}
 