#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n, -1);
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    int c = 1;
    int cur = a[i];
    bool check = false;
    priority_queue<int> que;
    que.push(i);
    for (int j = i + 1; j < n; j++) {
      if (abs(cur - a[j]) <= k) {
        if (b[j] >= 0) {
          c += b[j];
          if (maxi < c) {
            maxi = c;
          }
          check = true;
          break;
        } else {
          que.push(j);
          cur = a[j];
          c++;
        }
      }
    }
    if (check == true)
      continue;
    else {
      if (maxi < c) {
        maxi = c;
      }
      int cc = 0;
      while (!que.empty()) {
        int it = que.top();
        cc++;
        b[it] = cc;
        que.pop();
      }
    }
  }
  cout << maxi << endl;
}
