#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 300010;
int nxt = 0;
int root[N];
struct Node {
  int ls, rs, val, id = 0;
} node[N * 40];
void update(int &n, int pre, int b, int e, int pos, int id) {
  n = ++nxt;
  node[n] = node[pre];
  if (b == e && b == pos) {
    node[n].val++;
    node[n].id = max(node[n].id, id);
    node[n].ls = node[n].rs = 0;
    return;
  }
  int mid = (b + e) / 2;
  if (pos <= mid)
    update(node[n].ls, node[pre].ls, b, mid, pos, id);
  else
    update(node[n].rs, node[pre].rs, mid + 1, e, pos, id);
  node[n].val = node[node[n].ls].val + node[node[n].rs].val;
  node[n].id = max(node[node[n].ls].id, node[node[n].rs].id);
}
int q;
vector<int> A;
int query_sum(int root, int b, int e, int l, int r) {
  if (l > r) return 0;
  if (l > e || b > r) return 0;
  if (b == l && r == e) {
    return node[root].val;
  }
  int mid = (b + e) / 2;
  return query_sum(node[root].ls, b, mid, l, min(r, mid)) +
         query_sum(node[root].rs, mid + 1, e, max(l, mid + 1), r);
}
int query(int root, int b, int e, int l, int r) {
  if (l > r) return 0;
  if (l > e || b > r) return 0;
  if (b == l && r == e) return node[root].id;
  int mid = (b + e) / 2;
  return max(query(node[root].ls, b, mid, l, min(r, mid)),
             query(node[root].rs, mid + 1, e, max(l, mid + 1), r));
}
int main() {
  int n;
  cin >> n >> q;
  A.resize(n);
  for (int j = 0; j < n; ++j) {
    cin >> A[j];
    A[j]--;
  }
  vector<int> ans(n, 1);
  int res = 1;
  int K = 300000;
  for (int k = 1; k <= n; ++k)
    update(root[k], root[k - 1], 0, K - 1, A[k - 1], k - 1);
  for (int i = 1; i <= n; ++i) {
    int sum1 = query_sum(root[i - 1], 0, K - 1, max(A[i - 1] - q, 0), A[i - 1]);
    int sum2 =
        query_sum(root[i - 1], 0, K - 1, A[i - 1], min(K - 1, A[i - 1] + q));
    if (sum1) {
      int ind = query(root[i - 1], 0, K - 1, max(A[i - 1] - q, 0), A[i - 1]);
      ans[i - 1] = 1 + ans[ind];
    }
    if (sum2) {
      int ind =
          query(root[i - 1], 0, K - 1, A[i - 1], min(K - 1, A[i - 1] + q));
      ans[i - 1] = max(ans[i - 1], 1 + ans[ind]);
    }
    res = max(res, ans[i - 1]);
  }
  cout << res << "\n";
}
