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

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

#[allow(dead_code)]
fn read2<T : std::str::FromStr>() -> (T, T) {
  (read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn read3<T : std::str::FromStr>() -> (T, T, T) {
  (read::<T>(), read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn reads<T : std::str::FromStr>() -> Vec<T> {
  let mut line = String::new();
  stdin().read_line(&mut line).ok();
  line.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

struct MaxSegTree {
  n: usize,
  data: Vec<i64>,
}

impl MaxSegTree {
  fn new(data_: &[i64]) -> Self {
    let m = data_.len();
    let mut n = 1;
    while n < m { n *= 2; }

    let mut data = vec![std::i64::MIN; 2*n];

    for i in 0..m {
      data[i + n - 1] = data_[i];
    }

    for ri in 0..n-2 {
      let i = n - 2 - ri; // [n-2 .. 0]
      data[i] = max(data[i*2+1], data[i*2+2]);
    }

    Self {
      n,
      data,
    }
  }

  fn update(&mut self, i: usize, val: i64) {
    let mut i = self.n - 1 + i;
    self.data[i] = val;
    while i > 0 {
      i = (i - 1) / 2;
      self.data[i] = max(self.data[i*2+1], self.data[i*2+2]);
    }
  }

  fn query(&self, l: usize, r: usize) -> i64 {
    let mut l = l + self.n - 1;
    let mut r = r + self.n - 1;

    let mut res = std::i64::MIN;
    while l < r {
      if (l & 1) == 0 {
        res = max(res, self.data[l]);
      }
      if (r & 1) == 0 {
        res = max(res, self.data[r]);
      }
      l = l / 2;
      r = (r - 1) / 2;
    }

    res
  }
}

fn main() {
  let n: usize = read();
  let k: usize = read();
  let mut xs: Vec<usize> = Vec::with_capacity(n);
  for _ in 0..n {
    let x = read();
    xs.push(x);
  }

  const LIMIT: usize = 300000 + 10;
  let mut seg = MaxSegTree::new(&vec![0; LIMIT]);
  let mut res = 1;
  for x in xs {
    let l = if x >= k { x - k } else { 0 };
    let r = if x + k + 1 <= LIMIT { x + k + 1 } else { LIMIT };
    let head = seg.query(l, r);

    seg.update(x, head + 1);
    res = max(res, head + 1);
  }

  // let res = seg.query(0, LIMIT);
  println!("{}", res);
}