#include <bits/stdc++.h>
const int md = 998244353;
using namespace std;
using namespace std::chrono;
long long pw(long long a, long long b) {
  long long c = 1, m = a;
  while (b) {
    if (b & 1) c = (c * m);
    m = (m * m);
    b /= 2;
  }
  return c;
}
long long pwmd(long long a, long long b) {
  long long c = 1, m = a;
  while (b) {
    if (b & 1) c = (c * m) % md;
    m = (m * m) % md;
    b /= 2;
  }
  return c;
}
long long modinv(long long n) { return pwmd(n, md - 2); }
long long inverse(long long i) {
  if (i == 1) return 1;
  return (md - ((md / i) * inverse(md % i)) % md + md) % md;
}
long long ceel(long long a, long long b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
long long my_log(long long n, long long b) {
  long long i = 1;
  long long ans = 0;
  while (1) {
    if (i > n) {
      ans--;
      break;
    }
    if (i == n) break;
    i *= b;
    ans++;
  }
  return ans;
}
bool sortbysec(const pair<long long, long long>& a,
               const pair<long long, long long>& b) {
  return (a.second < b.second);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<char> capl = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                     'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                     'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> sml = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                    'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                    's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
string conv(long long a) {
  string b;
  long long e = 2;
  long long c = my_log(a, e);
  c++;
  b = '1';
  for (int i = 0; i < c - 1; i++) {
    long long k = a >> (c - 2 - i);
    if (k & 1)
      b += '1';
    else
      b += '0';
  }
  if (a == 0) return "0";
  return b;
}
long long mysqt(long long a) {
  long long ans = 1;
  while (ans * ans <= a) ans++;
  ans--;
  return ans;
}
bool isprime(int p) {
  int i = 2;
  while (i <= sqrt(p)) {
    if (p % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}
int getMid(int s, int e) { return s + (e - s) / 2; }
int MaxUtil(int* st, int ss, int se, int l, int r, int node) {
  if (l <= ss && r >= se) return st[node];
  if (se < l || ss > r) return -1;
  int mid = getMid(ss, se);
  return max(MaxUtil(st, ss, mid, l, r, 2 * node + 1),
             MaxUtil(st, mid + 1, se, l, r, 2 * node + 2));
}
void updateValue(int arr[], int* st, int ss, int se, int index, int value,
                 int node) {
  if (index < ss || index > se) {
    cout << "Invalid Input" << endl;
    return;
  }
  if (ss == se) {
    arr[index] = value;
    st[node] = value;
  } else {
    int mid = getMid(ss, se);
    if (index >= ss && index <= mid)
      updateValue(arr, st, ss, mid, index, value, 2 * node + 1);
    else
      updateValue(arr, st, mid + 1, se, index, value, 2 * node + 2);
    st[node] = max(st[2 * node + 1], st[2 * node + 2]);
  }
  return;
}
int getMax(int* st, int n, int l, int r) {
  if (l < 0 || r > n - 1 || l > r) {
    printf("Invalid Input");
    return -1;
  }
  return MaxUtil(st, 0, n - 1, l, r, 0);
}
int constructSTUtil(int arr[], int ss, int se, int* st, int si) {
  if (ss == se) {
    st[si] = arr[ss];
    return arr[ss];
  }
  int mid = getMid(ss, se);
  st[si] = max(constructSTUtil(arr, ss, mid, st, si * 2 + 1),
               constructSTUtil(arr, mid + 1, se, st, si * 2 + 2));
  return st[si];
}
int* constructST(int arr[], int n) {
  int x = (int)(ceil(log2(n)));
  int max_size = 2 * (int)pow(2, x) - 1;
  int* st = new int[max_size];
  constructSTUtil(arr, 0, n - 1, st, 0);
  return st;
}
int main() {
  int p, a, k;
  cin >> p >> k;
  int v[p];
  int mm = 0;
  for (int i = 0; i < p; i++) cin >> v[i], mm = max(mm, v[i]);
  int arr[mm + 1 + k];
  for (int i = 0; i < mm + 1 + k; i++) arr[i] = 0;
  int n = sizeof(arr) / sizeof(arr[0]);
  int* st = constructST(arr, n);
  int dp[p];
  for (int i = 0; i < p; i++) dp[i] = 1;
  dp[0] = 1;
  updateValue(arr, st, 0, n - 1, v[0], 1, 0);
  vector<int> vis(mm + 1);
  vis[v[0]] = 1;
  for (int i = 1; i < p; i++) {
    int q;
    if (vis[v[i]])
      q = getMax(st, n, max(0, v[i] - k), v[i] + k);
    else {
      q = getMax(st, n, max(0, v[i] - k), v[i] - 1);
      q = max(q, getMax(st, n, v[i] + 1, v[i] + k));
    }
    vis[v[i]] = 1;
    dp[i] = max(dp[i], q + 1);
    updateValue(arr, st, 0, n - 1, v[i], dp[i], 0);
  }
  int mx = 0;
  for (int i = 0; i < p; i++) mx = max(mx, dp[i]);
  cout << mx;
}
