#[allow(unused)]
use {
    std::error::Error,
    std::fmt::Debug,
    std::str::FromStr,
    std::io::prelude::*,
    std::io::{stdin, stdout, BufReader, BufWriter},
    std::collections::{HashSet, BinaryHeap},
    std::cmp::min,
    std::mem::swap,
    std::char::from_digit,
};

type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;

const M: usize = 300000;

fn main() -> BoxResult<()> {
    let mut scanner = Scanner::new(stdin());
    let (n, k) = scanner.read_two::<usize, usize>()?;
    let mut arr = vec![];
    for _ in 0..n {
        arr.push(scanner.read::<usize>()?);
    }
    let mut tree = SegmentTree::new(M + 1);
    for i in 0..n {
        let s = std::cmp::max(arr[i], k) - k;
        let e = std::cmp::min(arr[i] + k, M);
        let v = tree.query(s, e);
        tree.set(arr[i], v + 1);
    }
    

    println!("{}", tree.query(0, M));
    Ok(())
}

struct SegmentTree {
    size: usize,
    len: usize,
    values: Vec<usize>
}

impl SegmentTree {
    fn new(size: usize) -> Self {
        let mut len = 1;
        while len < size {
            len *= 2;
        }
        let values = vec![0; 2 * len - 1];
        Self {
            size,
            len,
            values
        }
    }

    fn set(&mut self, i: usize, x: usize) {
        self.set_rec(i, x, 0, 0, self.len - 1);
    }

    fn set_rec(&mut self, i: usize, x: usize, index: usize, l: usize, r: usize) {
        self.values[index] = std::cmp::max(x, self.values[index]);
        if l == r {
            return;
        }
        let mid = (l + r) / 2;
        if i <= mid {
            self.set_rec(i, x, 2 * index + 1, l, mid);
        } else {
            self.set_rec(i, x, 2 * index + 2, mid + 1, r);
        }
    }

    fn query(&self, s: usize, e: usize) -> usize {
        self.query_rec(s, e, 0, 0, self.len - 1)
    }

    fn query_rec(&self, s: usize, e: usize, index: usize, l: usize, r: usize) -> usize {
        let mid = (l + r) / 2;
        if s == l && e == r {
            return self.values[index];
        }
        if e <= mid {
            return self.query_rec(s, e, 2 * index + 1, l, mid);
        }
        if s > mid {
            return self.query_rec(s, e, 2 * index + 2, mid + 1, r);
        }
        let max_l = self.query_rec(s, mid, 2 * index + 1, l, mid);
        let max_r = self.query_rec(mid + 1, e, 2 * index + 2, mid + 1, r);
        return std::cmp::max(max_l, max_r);
    }
}

pub struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}
impl<R> Scanner<R>
where
    R: Read,
{
    pub fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    pub fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    pub fn read_line(&mut self) -> BoxResult<String> {
        self.reader.read_line(&mut self.buffer)?;
        let cloned = self.buffer.trim().to_string();
        self.buffer.clear();
        Ok(cloned)
    }
 
    pub fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }
    pub fn read_two<T, U>(&mut self) -> BoxResult<(T, U)>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
        U: FromStr + Copy,
        U::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            (a, b)
        };
        self.buffer.clear();
        Ok((a, b))
    }
    pub fn read_three<T, U, V>(&mut self) -> BoxResult<(T, U, V)>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
        U: FromStr + Copy,
        U::Err: Debug + Error + 'static,
        V: FromStr + Copy,
        V::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b, c) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            let c = params[2].parse()?;
            (a, b, c)
        };
        self.buffer.clear();
        Ok((a, b, c))
    }
    pub fn read_four<T, U, V, W>(&mut self) -> BoxResult<(T, U, V, W)>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
        U: FromStr + Copy,
        U::Err: Debug + Error + 'static,
        V: FromStr + Copy,
        V::Err: Debug + Error + 'static,
        W: FromStr + Copy,
        W::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b, c, d) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            let c = params[2].parse()?;
            let d = params[3].parse()?;
            (a, b, c, d)
        };
        self.buffer.clear();
        Ok((a, b, c, d))
    }
    pub fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }
    pub fn read_matrix<T>(&mut self, lines: u64) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
    pub fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}

Measured memory_bytes: 9144