#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
void swap(long long *a, long long *b) {
  long long c;
  c = *b;
  *b = *a;
  *a = c;
}
void cin(long long *n) { scanf("%lld", &(*n)); }
void PriAll1(long long a[], long long n) {
  for (long long i = (0); i < (n); i++) {
    printf("%lld", a[i]);
    if (i != n - 1) printf(" ");
  }
  printf("\n");
}
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a < b ? b : a; }
long long min3(long long a, long long b, long long c) {
  return (a <= b && a <= c) ? a : b <= c ? b : c;
}
long long max3(long long a, long long b, long long c) {
  return (a >= b && a >= c) ? a : b >= c ? b : c;
}
long long minn(long long n, long long a[]) {
  long long b = (1LL << 62);
  for (long long i = (0); i < (n); i++) b = min(b, a[i]);
  return b;
}
long long maxn(long long n, long long a[]) {
  long long b = -(1LL << 62);
  for (long long i = (0); i < (n); i++) b = max(b, a[i]);
  return b;
}
long long POW(long long a, long long b) {
  long long c = 1;
  for (long long i = (0); i < (b); i++) c *= a;
  return c;
}
double POW_d(double a, double b) {
  double c = 1;
  for (long long i = (0); i < (b); i++) c *= a;
  return c;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long mod_MOD1(long long n) {
  n += n < 0 ? ((-n) / 1000000007 + 1) * 1000000007 : 0;
  return n %= 1000000007;
}
long long mod_p(long long n, long long p) {
  n += n < 0 ? ((-n) / p + 1) * p : 0;
  return n %= p;
}
long long change_into_num(char s[], long long len, long long p) {
  return !p ? 0
            : POW(10, p - 1) * (s[len - p] - '0') +
                  change_into_num(s, len, p - 1);
}
long long digits(long long a, long long b) {
  return a / b ? 1 + digits(a / b, b) : 1;
}
long long base(long long n, long long a, long long i) {
  return i == 1 ? n % a : base(n / a, a, i - 1);
}
long long is_inArr1(long long x, long long n) {
  return (x < 0 || x >= n) ? 0 : 1;
}
long long is_inArr2(long long y, long long x, long long h, long long w) {
  return (y < 0 || y >= h || x < 0 || x >= w) ? 0 : 1;
}
void lr_lower(int *l, int *r, long long am, long long val, int type) {
  (type < 3) ? (am < val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2))
             : (am <= val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2));
}
void lr_upper(int *l, int *r, long long am, long long val, int type) {
  (type < 3) ? (am <= val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2))
             : (am < val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2));
}
int cmp_lower(long long a, long long b, int type) {
  return (type == 1)   ? (a == b ? 1 : 0)
         : (type == 2) ? (a >= b ? 1 : 0)
                       : (a > b ? 1 : 0);
}
int cmp_upper(long long a, long long b, int type) {
  return (type == 1)   ? (a == b ? 1 : 0)
         : (type == 2) ? (a <= b ? 1 : 0)
                       : (a < b ? 1 : 0);
}
long long lower_bound(long long a[], int l, int r, long long val, int type) {
  while (r - l > 1) lr_lower(&l, &r, a[(l + r) / 2], val, type);
  return cmp_lower(a[l], val, type) ? l : cmp_lower(a[r], val, type) ? r : -1;
}
long long upper_bound(long long a[], int l, int r, long long val, int type) {
  while (r - l > 1) lr_upper(&l, &r, a[(l + r) / 2], val, type);
  return cmp_upper(a[r], val, type) ? r : cmp_upper(a[l], val, type) ? l : -1;
}
long long count(long long a[], int l, int r, long long x) {
  int p = lower_bound(a, l, r, x, 1);
  return p == -1 ? 0 : upper_bound(a, p, r, x, 1) - p + 1;
}
long long *factors[2], fac_cnt = 0, is_factor_prepared = 0;
long long factor_pre() {
  for (long long i = (0); i < (1); i++) {
    if (is_factor_prepared++) return 0;
  }
  long long tmp = (1e6) / 2 + 1, fac_tmp[tmp];
  for (long long i = (0); i < (tmp); i++) {
    fac_tmp[i] = i ? 2 * i + 1 : 2;
  }
  for (long long i = (1); i < (tmp); i++) {
    if (fac_tmp[i]) {
      for (long long j = (3); j < (tmp / (2 * i + 1) + 1); j += (2)) {
        if (j * (2 * i + 1) < tmp) fac_tmp[(j * (2 * i + 1) - 1) / 2] = 0;
      }
    } else
      continue;
  }
  for (long long i = (0); i < (tmp); i++) {
    if (fac_tmp[i]) {
      for (long long j = (0); j < (2); j++) {
        factors[j] =
            (long long *)realloc(factors[j], sizeof(long long) * (fac_cnt + 1));
        factors[j][j ? fac_cnt++ : fac_cnt] = j ? 0 : fac_tmp[i];
      }
    }
  }
  return 0;
}
long long factor(long long n, long long new_common_plus) {
  factor_pre();
  for (long long i = (0); i < (fac_cnt); i++) {
    long long cnt = 0;
    for (long long j = (0); j < (1); j++) {
      while ((cnt += n % factors[0][i] == 0 ? 1 : 0) &&
             (n /= factors[0][i]) % factors[0][i] == 0)
        continue;
    }
    factors[1][i] = new_common_plus == 1   ? cnt
                    : new_common_plus == 2 ? max(factors[1][i], cnt)
                                           : factors[1][i] + cnt;
    if (factors[0][i] > n) break;
  }
  return n;
}
long long judge_prime(long long n) {
  factor_pre();
  for (long long i = (0); i < (fac_cnt); i++) {
    if (n < factors[0][i] * factors[0][i] || n == factors[0][i])
      break;
    else if (n % factors[0][i] == 0)
      n /= n;
  }
  return n == 1 ? 0 : 1;
}
long long *mf_arr, *inv_arr, *finv_arr, is_minv_made = 0, is_mf_made = 0,
                                        num_of_inv = 2 * 1e6 + 10;
long long makeinv(long long n, long long mod) {
  for (long long i = (0); i < (1); i++) {
    if (is_minv_made++) return 0;
  }
  inv_arr = (long long *)realloc(inv_arr, sizeof(long long) * 2);
  finv_arr = (long long *)realloc(finv_arr, sizeof(long long) * 2);
  inv_arr[1] = 1;
  finv_arr[0] = finv_arr[1] = 1;
  for (long long i = (2); i < (n + 1); i++) {
    inv_arr = (long long *)realloc(inv_arr, sizeof(long long) * (i + 1));
    finv_arr = (long long *)realloc(finv_arr, sizeof(long long) * (i + 1));
    inv_arr[i] = mod - inv_arr[mod % i] * (mod / i) % mod;
    finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod;
  }
  return 0;
}
long long make_mf(long long n, long long mod) {
  for (long long i = (0); i < (1); i++) {
    if (is_mf_made++) return 0;
  }
  mf_arr = (long long *)realloc(mf_arr, sizeof(long long) * 2);
  long long x = 1;
  mf_arr[0] = mf_arr[1] = x;
  for (long long i = (2); i < (n + 1); i++) {
    x = x * i % mod;
    mf_arr = (long long *)realloc(mf_arr, sizeof(long long) * (i + 1));
    mf_arr[i] = x;
  }
  return 0;
}
long long m_inv(long long x, long long mod, long long is_fac) {
  makeinv(num_of_inv, mod);
  return is_fac ? finv_arr[x] : inv_arr[x];
}
long long m_f(long long x, long long mod) {
  make_mf(num_of_inv, mod);
  return mf_arr[x];
}
long long mod_nck(long long n, long long k, long long mod) {
  return m_f(n, mod) * m_inv(k, mod, 1) % mod * m_inv(n - k, mod, 1) % mod;
}
long long m_p(long long r, long long n, long long mod) {
  long long t = 1, s = r;
  while (n > 0) {
    t = (n & 1) ? t * s % mod : t;
    s = s * s % mod;
    n >>= 1;
  }
  return r ? t : 0;
}
long long m_mul2(long long a, long long b, long long mod) {
  return a * b % mod;
}
long long m_mul3(long long a, long long b, long long c, long long mod) {
  return m_mul2(a * b % mod, c, mod);
}
long long m_mul4(long long a, long long b, long long c, long long d,
                 long long mod) {
  return m_mul3(a * b % mod, c, d, mod);
}
long long m_mul5(long long a, long long b, long long c, long long d,
                 long long e, long long mod) {
  return m_mul4(a * b % mod, c, d, e, mod);
}
int upll(const void *a, const void *b) {
  return *(long long *)a < *(long long *)b   ? -1
         : *(long long *)a > *(long long *)b ? 1
                                             : 0;
}
int downll(const void *a, const void *b) {
  return *(long long *)a < *(long long *)b   ? 1
         : *(long long *)a > *(long long *)b ? -1
                                             : 0;
}
int cmp_string(const void *a, const void *b) {
  return strcmp((char *)a, (char *)b);
}
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }
void sortup(long long *a, int n) { qsort(a, n, sizeof(long long), upll); }
void sortdown(long long *a, int n) { qsort(a, n, sizeof(long long), downll); }
long long compare(long long a, long long b) {
  return a < b ? -1 : a > b ? 1 : 0;
}
typedef struct {
  long long a, b;
} fr;
int cmp1(const void *p, const void *q) {
  long long pa = ((fr *)p)->a;
  long long qa = ((fr *)q)->a;
  return compare(pa, qa);
}
int cmp2(const void *p, const void *q) {
  long long pa = ((fr *)p)->a;
  long long qa = ((fr *)q)->a;
  return compare(qa, pa);
}
void strsortup(fr *a, int n) { qsort(a, n, sizeof(fr), cmp1); }
void strsortdown(fr *a, int n) { qsort(a, n, sizeof(fr), cmp2); }
void sort_partial(long long a[], int begin, int end, int is_increase) {
  long long *b;
  b = (long long *)malloc(sizeof(long long) * (end - begin));
  for (long long i = (begin); i < (end); i++) b[i - begin] = a[i];
  if (is_increase)
    sortup(b, end - begin);
  else
    sortdown(b, end - begin);
  for (long long i = (begin); i < (end); i++) a[i] = b[i - begin];
}
typedef struct node_AVL_set {
  long long val;
  int diff;
  int cnt;
  struct node_AVL_set *child[2];
} AVL_set;
void AVL_set_inside_rotate(AVL_set **node, int is_right) {
  int l = is_right == false, r = is_right == true, sign = is_right ? 1 : -1;
  if ((*node)->child[l] != NULL) {
    AVL_set *left = (*node)->child[l];
    int a = (*node)->diff * sign, b = left->diff * sign, na, nb;
    if (b + 1) {
      na = a - 1 - b;
      nb = (a - b) ? b - 1 : a - 2;
    } else {
      na = a - 1;
      nb = a ? b - 1 : a + b - 2;
    }
    (*node)->diff = na * sign;
    left->diff = nb * sign;
    (*node)->child[l] = (*node)->child[l]->child[r];
    left->child[r] = *node;
    *node = left;
  }
}
int AVL_set_inside_update(AVL_set **node, long long data, int add) {
  if (*node == NULL) {
    if (add == 2) {
      *node = (AVL_set *)malloc(sizeof(AVL_set));
      (*node)->val = data;
      (*node)->cnt = 1;
      (*node)->diff = 0;
      (*node)->child[0] = NULL;
      (*node)->child[1] = NULL;
    }
    return add == 2 ? *node != NULL : 0;
  } else {
    int l, delta, delta_sign;
    AVL_set *next_node;
    if (data == (*node)->val) {
      if (add == 2) {
        (*node)->cnt++;
        return 0;
      } else {
        if (add && (*node)->cnt > 1) {
          (*node)->cnt--;
          return 0;
        } else {
          if ((*node)->child[1] == NULL) {
            next_node = (*node)->child[0];
            free(*node);
            *node = next_node;
            return -1;
          } else if ((*node)->child[0] == NULL) {
            next_node = (*node)->child[1];
            free(*node);
            *node = next_node;
            return -1;
          } else {
            for (next_node = (*node)->child[0]; next_node->child[1] != NULL;
                 next_node = next_node->child[1])
              ;
            (*node)->val = next_node->val;
            l = 0;
            delta_sign = 1;
            delta =
                AVL_set_inside_update(&(*node)->child[l], next_node->val, add);
          }
        }
      }
    } else {
      l = data >= (*node)->val ? 1 : 0;
      delta_sign = data < (*node)->val ? 1 : -1;
      delta = AVL_set_inside_update(&(*node)->child[l], data, add);
    }
    if (delta) {
      int orig_diff = (*node)->diff;
      int do_rotate = 0, rotate_l, diff_sign, rotate_right;
      (*node)->diff += delta * delta_sign;
      if ((*node)->diff > 1) {
        do_rotate = 1;
        rotate_l = 0;
        diff_sign = 1;
        rotate_right = 1;
      } else if ((*node)->diff < -1) {
        do_rotate = 1;
        rotate_l = 1;
        diff_sign = -1;
        rotate_right = 0;
      }
      if (do_rotate) {
        int child_diff = (*node)->child[rotate_l]->diff;
        if ((*node)->child[rotate_l]->diff * diff_sign < 0) {
          AVL_set_inside_rotate(&(*node)->child[rotate_l], !rotate_right);
        }
        AVL_set_inside_rotate(node, rotate_right);
        return delta < 0 && child_diff != 0 ? -1 : 0;
      }
      if (delta > 0 && orig_diff == 0)
        return 1;
      else if (delta < 0 && orig_diff != 0)
        return -1;
      else
        return 0;
    } else {
      return 0;
    }
  }
}
void AVL_set_inside_print(const AVL_set *node, int depth) {
  if (node == NULL) return;
  AVL_set_inside_print(node->child[1], depth + 1);
  printf("%lld %d\n", node->val, node->cnt);
  AVL_set_inside_print(node->child[0], depth + 1);
}
void AVL_set_inside_free(AVL_set *node) {
  if (node == NULL) return;
  AVL_set_inside_free(node->child[0]);
  AVL_set_inside_free(node->child[1]);
  free(node);
}
long long AVL_set_inside_count(AVL_set *root, long long val) {
  AVL_set *node;
  node = root;
  while (node) {
    if (val < node->val)
      node = node->child[0];
    else if (val > node->val)
      node = node->child[1];
    else
      return node->cnt;
  }
  return 0;
}
int AVL_set_lowcomp(long long node, long long val, int type) {
  if (node == val) {
    if (type != 3)
      return 0;
    else
      return 1;
  }
  if (node < val) return 1;
  if (node > val) return -1;
  return 0;
}
AVL_set *AVL_set_inside_lowerbound(AVL_set *root, long long val, int type) {
  AVL_set *node;
  node = root;
  while (node) {
    int com = AVL_set_lowcomp(node->val, val, type);
    if (com == 0) return node;
    if (com == 1) node = node->child[1];
    if (com == -1) {
      AVL_set *small;
      small = AVL_set_inside_lowerbound(node->child[0], val, type);
      if (type == 1) {
        return small;
      } else {
        if (small != NULL)
          return small;
        else
          return node;
      }
    }
  }
  return node;
}
int AVL_set_upcomp(long long node, long long val, int type) {
  if (node == val) {
    if (type != 3)
      return 0;
    else
      return -1;
  }
  if (node < val) return 1;
  if (node > val) return -1;
  return 0;
}
AVL_set *AVL_set_inside_upperbound(AVL_set *root, long long val, int type) {
  AVL_set *node;
  node = root;
  while (node) {
    int com = AVL_set_upcomp(node->val, val, type);
    if (com == 0) return node;
    if (com == -1) node = node->child[0];
    if (com == 1) {
      AVL_set *big;
      big = AVL_set_inside_upperbound(node->child[1], val, type);
      if (type == 1) {
        return big;
      } else {
        if (big != NULL)
          return big;
        else
          return node;
      }
    }
  }
  return node;
}
long long AVL_set_inside_minmax(AVL_set *root, int type) {
  while (root->child[type] != NULL) root = root->child[type];
  return root->val;
}
void AVL_set_inside_swap(AVL_set **node1, AVL_set **node2) {
  AVL_set *tmp;
  tmp = *node1;
  *node1 = *node2;
  *node2 = tmp;
}
long long set_main(int command, int set_num, long long val, long long option) {
  static bool set_is_init = false;
  static AVL_set *set_pointer[514511];
  static long long set_siz[514511];
  if (!set_is_init) {
    set_is_init = true;
    for (long long i = (0); i < (514511); i++) {
      *(set_pointer + i) = NULL;
      set_siz[i] = 0;
    }
  }
  if (command == -1) {
    AVL_set_inside_print(set_pointer[set_num], 0);
  }
  if (command == 1) {
    AVL_set_inside_count(set_pointer[set_num], val) ? 1 : set_siz[set_num]++;
    AVL_set_inside_update(&set_pointer[set_num], val, 2);
  }
  if (command == 2) {
    return AVL_set_inside_count(set_pointer[set_num], val);
  }
  if (command == 3) {
    (AVL_set_inside_count(set_pointer[set_num], val) > 1) ? 1
                                                          : set_siz[set_num]--;
    AVL_set_inside_update(&set_pointer[set_num], val, 1);
  }
  if (command == 4) {
    set_siz[set_num]--;
    AVL_set_inside_update(&set_pointer[set_num], val, 0);
  }
  if (command == 5) {
    set_siz[set_num] = 0;
    AVL_set_inside_free(set_pointer[set_num]);
    set_pointer[set_num] = NULL;
  }
  if (command == 6) {
    return set_siz[set_num];
  }
  if (command == 7) {
    return AVL_set_inside_minmax(set_pointer[set_num], 1);
  }
  if (command == 8) {
    return AVL_set_inside_minmax(set_pointer[set_num], 0);
  }
  if (command == 9) {
    AVL_set_inside_swap(&set_pointer[set_num], &set_pointer[val]);
  }
  if (10 <= command && command <= 12) {
    AVL_set *lowbound =
        AVL_set_inside_lowerbound(set_pointer[set_num], val, command - 9);
    if (lowbound == NULL)
      return option;
    else
      return lowbound->val;
  }
  if (13 <= command && command <= 15) {
    AVL_set *upbound =
        AVL_set_inside_upperbound(set_pointer[set_num], val, command - 12);
    if (upbound == NULL)
      return option;
    else
      return upbound->val;
  }
  return 0;
}
void set_print(int set_num) { set_main(-1, set_num, 0, 0); }
void set_insert(int set_num, long long val) { set_main(1, set_num, val, 0); }
long long set_count(int set_num, long long val) {
  return set_main(2, set_num, val, 0);
}
void set_erase(int set_num, long long val, int is_all) {
  if (is_all)
    set_main(4, set_num, val, 0);
  else
    set_main(3, set_num, val, 0);
}
void set_clear(int set_num) { set_main(5, set_num, 0, 0); }
long long set_size(int set_num) { return set_main(6, set_num, 0, 0); }
long long set_max(int set_num) { return set_main(7, set_num, 0, 0); }
long long set_min(int set_num) { return set_main(8, set_num, 0, 0); }
void set_swap(int set_num1, int set_num2) {
  set_main(9, set_num1, set_num2, 0);
}
long long set_lowerbound(int set_num, long long val, int type,
                         long long error) {
  return set_main(9 + type, set_num, val, error);
}
long long set_upperbound(int set_num, long long val, int type,
                         long long error) {
  return set_main(12 + type, set_num, val, error);
}
long long seg_e_max() { return -(1LL << 62); }
long long seg_e_min() { return (1LL << 62); }
long long seg_e_sum() { return 0; }
long long seg_e_gcd() { return 0; }
long long seg_op_max(long long a, long long b) { return max(a, b); }
long long seg_op_min(long long a, long long b) { return min(a, b); }
long long seg_op_sum(long long a, long long b) { return a + b; }
long long seg_op_gcd(long long a, long long b) { return gcd(a, b); }
typedef struct seg_tree {
  int _n;
  long long *node;
  long long (*op)(long long, long long);
  long long (*e)(void);
  long long (*get)(struct seg_tree *, int);
  long long (*prod)(struct seg_tree *, int, int);
  void (*update)(struct seg_tree *, int, long long);
} struct seg_tree;
long long seg_get(struct seg_tree *S, int x) { return S->node[S->_n / 2 + x]; }
long long seg_prod_inner(struct seg_tree *S, int l, int r, int x, int from,
                         int to) {
  if (l <= from && to <= r) return S->node[x];
  if (r < from || to < l) return S->e();
  return S->op(seg_prod_inner(S, l, r, 2 * x + 1, from, (from + to) / 2),
               seg_prod_inner(S, l, r, 2 * x + 2, (from + to) / 2 + 1, to));
}
long long seg_prod(struct seg_tree *S, int l, int r) {
  return seg_prod_inner(S, l, r, 0, 0, S->_n / 2);
}
void seg_update(struct seg_tree *S, int x, long long val) {
  long long c = S->_n / 2 + x;
  S->node[c] = val;
  while (c > 0) {
    c--;
    c /= 2;
    S->node[c] = S->op(S->node[2 * (c + 1)], S->node[2 * (c + 1) - 1]);
  }
}
struct seg_tree *seg_init(int n, long long a[],
                          long long (*op)(long long, long long),
                          long long (*e)()) {
  struct seg_tree *ret = (struct seg_tree *)malloc(sizeof(struct seg_tree));
  int x = 1;
  ret->_n = 0;
  while (x < n) {
    ret->_n += x;
    x *= 2;
  }
  ret->_n += x;
  ret->node = (long long *)malloc(ret->_n * sizeof(long long));
  ret->op = op;
  ret->e = e;
  ret->get = seg_get;
  ret->prod = seg_prod;
  ret->update = seg_update;
  if (a == NULL) {
    for (long long i = (0); i < (x); i++) {
      ret->node[x - 1 + i] = ret->e();
    }
  } else {
    for (long long i = (0); i < (x); i++) {
      if (i < n)
        ret->node[x - 1 + i] = a[i];
      else
        ret->node[x - 1 + i] = ret->e();
    }
  }
  while (x /= 2) {
    for (long long i = (0); i < (x); i++) {
      int p = 2 * (x + i);
      ret->node[x + i - 1] = ret->op(ret->node[p], ret->node[p - 1]);
    }
  }
  return ret;
}
long long dp[366366];
void solve() {
  long long n, k;
  long long ans = 0;
  cin(&n);
  cin(&k);
  long long a[n];
  for (long long i = (0); i < (n); i++) {
    cin(&a[i]);
  }
  long long siz = 651651;
  struct seg_tree *s = seg_init(siz, NULL, seg_op_max, seg_e_max);
  s->update(s, a[0], 1);
  for (long long i = (1); i < (n); i++) {
    long long v = s->prod(s, max(0, a[i] - k), min(siz - 1, a[i] + k));
    s->update(s, a[i], v + 1);
  }
  printf("%lld\n", s->prod(s, 0, siz - 1));
}
int main(void) {
  long long T = 1;
  for (long long i = (0); i < (T); i++) {
    solve();
  }
  return 0;
}
