#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL << 60;
constexpr long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
class AdjListNode {
  int v;
  int weight;

 public:
  AdjListNode(int _v, int _w) {
    v = _v;
    weight = _w;
  }
  int getV() { return v; }
  int getWeight() { return weight; }
};
class Graph {
  int V;
  list<AdjListNode>* adj;
  void topologicalSortUtil(int v, bool visited[], stack<int>& Stack);

 public:
  Graph(int V);
  ~Graph();
  void addEdge(int u, int v, int weight);
  void longestPath(int s);
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<AdjListNode>[V];
}
Graph::~Graph() { delete[] adj; }
void Graph::addEdge(int u, int v, int weight) {
  AdjListNode node(v, weight);
  adj[u].push_back(node);
}
void Graph::topologicalSortUtil(int v, bool visited[], stack<int>& Stack) {
  visited[v] = true;
  list<AdjListNode>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i) {
    AdjListNode node = *i;
    if (!visited[node.getV()]) topologicalSortUtil(node.getV(), visited, Stack);
  }
  Stack.push(v);
}
void Graph::longestPath(int s) {
  stack<int> Stack;
  int dist[V];
  bool* visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) topologicalSortUtil(i, visited, Stack);
  for (int i = 0; i < V; i++) dist[i] = INT_MIN;
  dist[s] = 0;
  while (Stack.empty() == false) {
    int u = Stack.top();
    Stack.pop();
    list<AdjListNode>::iterator i;
    if (dist[u] != INT_MIN) {
      for (i = adj[u].begin(); i != adj[u].end(); ++i)
        if (dist[i->getV()] < dist[u] + i->getWeight())
          dist[i->getV()] = dist[u] + i->getWeight();
    }
  }
  int ans = 0;
  for (int i = 0; i < V; i++) {
    if (dist[i] != INT_MIN) {
      ans = max(dist[i] + 1, ans);
    }
  }
  cout << ans << endl;
  delete[] visited;
}
void Main() {
  int n, k;
  cin >> n >> k;
  vector<int> av(n);
  Graph g(n);
  for (int i = (0); i < (n); ++i) cin >> av[i];
  for (int i = (0); i < (n); ++i) {
    for (int j = (i + 1); j < (n); ++j) {
      if (abs(av[i] - av[j]) <= k) {
        g.addEdge(i, j, 1);
      }
    }
  }
  int s = 1;
  g.longestPath(s);
  return;
}
int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(15);
  int t = 1;
  for (int _ = (0); _ < (t); ++_) Main();
  return 0;
}
