#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <atcoder/all>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
using namespace atcoder;
using mint = modint998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;

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

int e() { return -1; }

segtree<int, op, e> seg(300100);
vector<int> ho(300100);

int main(){
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> ho[i];
		ho[i]--;
	}

	seg.set(ho[0], 1);
	for (int i = 1; i < n; i++){
		seg.set(ho[i], 1 + seg.prod(max(0, ho[i]-k), min(n-1, ho[i]+k)+1));
	}

	cout << seg.all_prod() << endl;
	return 0;
}
