use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

struct SegTree {
    nodes: Vec<usize>,
    size: usize,
}

impl SegTree {
    fn new(size: usize) -> Self {
        Self { nodes: vec![0; 4 * size + 10], size }
    }

    fn max(&self, l: usize, r: usize) -> usize {
        self.get_max(0, 0, self.size, l, r)
    }

    fn get_max(&self, node: usize, le: usize, ri: usize, l: usize, r: usize) -> usize {
        if l <= le && ri <= r {
            return self.nodes[node];
        }

        let mi = le + (ri - le) / 2;
        let mut res = 0;
        if l <= mi {
            res = cmp::max(res, self.get_max(self.left(node), le, mi, l, r));
        }
        if mi < r {
            res = cmp::max(res, self.get_max(self.right(node), mi + 1, ri, l, r));
        }
        res
    }

    fn update(&mut self, pos: usize, val: usize) {
        self.do_update(0, 0, self.size, pos, val)
    }

    fn do_update(&mut self, node: usize, le: usize, ri: usize, pos: usize, val: usize) {
        if le == ri {
            self.nodes[node] = cmp::max(self.nodes[node], val);
            return;
        }

        let mi = le + (ri - le) / 2;
        if pos <= mi {
            self.do_update(self.left(node), le, mi, pos, val);
        } else {
            self.do_update(self.right(node), mi + 1, ri, pos, val);
        }
        self.nodes[node] = cmp::max(
            self.nodes[self.left(node)],
            self.nodes[self.right(node)]
        );
    }

    fn left(&self, node: usize) -> usize {
        node * 2 + 1
    }

    fn right(&self, node: usize) -> usize {
        node * 2 + 2
    }
}

fn main() {
    let mut reader = TokenReader::new();
    let n = reader.next();
    let k: i32 = reader.next();

    let mut best = SegTree::new(1e5 as usize + 10);
    let mut res = 0;

    for _ in 0..n {
        let num: usize = reader.next();
        let l = cmp::max(0, num as i32 - k) as usize;
        let r = num + k as usize;

        let curr = best.max(l, r) + 1;
        best.update(num, curr);
        res = cmp::max(res, curr);
    }
    println!("{}", res);
}
