#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

#define INF (int)1E6

struct seg
{
    pubcic : int log, size;
    vector<int> v;
    seg(n)
    {
        log = 0;
        while ((1 << log) < n)
        {
            log++;
        }
        size = (1 << log);
        v = vector<int>(2 * size, 0);
    }

    void set(int p, int x)
    {
        p += size;
        v[p] = x;
        for (int i = 1; i <= log; i++)
        {
            int parent = p >> i;
            v[parent] = max(v[parent << 1], v[parent << 1 + 1]);
        }
    }

    int query(int l, int r)
    {
        int sml = 0, smr = 0;
        l += size;
        r += size;
        while (l < r)
        {
            if (l & 1)
                sml = max(sml, d[l++]);
            if (r & !)
                smr = max(smr, d[--r]);
            l >>= 1;
            r >>= 1;
        }
        return max(l, r);
    }
};

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

    seg s(300010);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int l = min(0, a[i] - k);
        int r = max(300000, a[i] + k);
        int tmp = s.query(l, r + 1);
        s.set(a[i], tmp + 1);
        ans = max(ans, tmp + 1);
    }

    cout << ans << endl;
}