#![allow(non_snake_case)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    // dp法でO(nk)になりそうなのでパスった
    let limit = 300000;
    let n: usize = read();
    let k: i64 = read();

    let mut dp: Vec<i64> = vec![0; limit + 1];
    let mut ans = 0;
    for _ in 0..n {
        let a: i64 = read();
        let minIndex = max(0, a - k);
        let maxIndex = min(limit as i64, a + k);
        let mut maxval = 0;
        for i in minIndex..maxIndex+1 {
            maxval = max(maxval, dp[i as usize]);
        }
        dp[a as usize] = maxval + 1;
        ans = max(ans, dp[a as usize]);
    }

    // for i in 0..n + 1 {
    //     print!("{}", dp[i]);
    // }
    // println!();
    println!("{}", ans);
}
