#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
unsigned GetDigit(unsigned num) { return std::to_string(num).length(); }
int tow(int n) {
  if (n == 0) return 1;
  int x = tow(n / 2);
  x *= x;
  if (n % 2 == 1) x *= 2;
  return x;
}
long long int KETAWA(long long int n) {
  long long int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
unsigned ND(unsigned num) { return std::to_string(num).length(); }
bool KIBN(string s) {
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - 1 - i]) return false;
  }
  return true;
}
bool SEISU(double n) {
  if (ceil(n) == floor(n)) {
    return true;
  } else
    return false;
}
bool KISU(int n) {
  if (n % 2 == 0)
    return false;
  else
    return true;
}
bool GUSU(int n) {
  if (n % 2 == 0)
    return true;
  else
    return false;
}
bool SOSU(int n) {
  if (n <= 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
char CHARHENKAN(char ch) {
  if ('a' <= ch && ch <= 'z') {
    return static_cast<char>(ch - 32);
  } else if ('A' <= ch && ch <= 'Z') {
    return static_cast<char>(ch + 32);
  } else {
    return ch;
  }
}
string STHENKAN(string s) {
  string ans;
  for (int i = 0; i < s.size(); i++) {
    ans += CHARHENKAN(s[i]);
  }
  return ans;
}
long long int max(long long int a, long long int b) {
  if (a < b) {
    return b;
  } else {
    return a;
  }
}
long long int KAIJOU(long long int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum %= 1000000007;
    sum *= i;
    sum %= 1000000007;
  }
  return sum;
}
const long long mod = 1000000007;
long long powmod(long long x, long long y) {
  long long res = 1;
  for (long long i = 0; i < y; i++) {
    res = res * x % mod;
  }
  return res;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int n, k, a, ans = 0, count = 0, next = 0;
  cin >> n >> k;
  vector<long long int> array(0, 0), barray(n, 0), carray, darray;
  for (int i = 0; i < n; i++) {
    cin >> a;
    array.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (array.at(i) - k <= array.at(j) && array.at(i) + k >= array.at(j)) {
        barray.at(i) = j;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    next = i;
    while (1) {
      if (barray.at(next) == 0) break;
      next = barray.at(next);
      count++;
    }
    ans = max(ans, count);
    count = 0;
  }
  cout << ans + 1 << endl;
  return 0;
}
