use std::io::Read;
use std::cmp;

struct SegTree {
  data : Vec<usize>,
  offset : usize
}
impl SegTree {
  fn new(n: usize) -> SegTree {
    let offset = n.next_power_of_two();
    let data = vec![0_usize; 2 * offset];
    SegTree{ data, offset }
  }
  fn update(&mut self, x :usize, v: usize) {
    self.data[self.offset + x] = v;
    let mut k = (self.offset + x) / 2;
    while k > 0 {
      self.data[k] = cmp::max(self.data[2 * k], self.data[2 * k + 1]);
      k /= 2;
    }
  }
  fn range_max(&self, a:usize, b:usize) -> usize {
    self.rmax(a, b, 1, 0, self.offset)
  }
  fn rmax(&self, a:usize, b:usize, k:usize, l:usize, r:usize) -> usize {
    if r <= a || b <= l {
      0
    } else if a <= l && r <= b {
      self.data[k]
    } else {
      let mid = (l + r) / 2;
      cmp::max(self.rmax(a,b,2 * k,l,mid), self.rmax(a,b,2 * k + 1, mid, r))
    }
  }
  fn max(&self) -> usize {
    self.data[1]
  }
}

fn main() {
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let A : Vec<usize> = buf.split_whitespace().map(|x|x.parse().unwrap()).collect();
  let N = A[0];
  let K = A[1];
  let mut st = SegTree::new(300_100);
  for &a in &A[2 ..] {
    let s = cmp::max(0, (a as isize) - (K as isize)) as usize;
    let t = cmp::min(300_100, (a as isize) + (K as isize) + 1) as usize;
    let v = st.range_max(a - K, a + K + 1);
    st.update(a, v + 1);
  }
  println!("{}", st.max());
}


