#include<bits/stdc++.h>
#define endl "\n"
#define PI acos(-1)
#define BMW_GTR ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef long long ll;
using namespace std;

//ll const n = 50005;

int arr[300005];

int longest_subseq(int n, int k)
{
    vector<int> dp(n, 0);

    int max_length[n + 1000] = {};

    for (int i = 0; i < n; i++)
    {
        int curr = arr[i];

        int lower = max(0, curr - k);

        int upper = min(n, curr + k);

        for (int j = lower; j < upper + 1; j++)
        {
            dp[i] = max(dp[i], max_length[j] + 1);
        }

        max_length[curr] = max(dp[i], max_length[curr]);
    }

    int ans = 0;

    for(int i:dp)ans = max(i, ans);

    return ans;
}

int main()
{
    BMW_GTR;

    int N, K;
    cin >> N >> K;

    for(int i = 0; i < N; i++)
    {
        cin >> arr[i];
    }

    cout << (longest_subseq(N, K));
    return 0;
}

