#include <bits/stdc++.h>
using namespace std;
int N, K, As[300007], memo[300007];
int subsolve(int i) {
  if (memo[i] != -1) return memo[i];
  int a = As[i];
  int l = 1;
  int r = 1;
  bool lf = false;
  bool rf = false;
  for (int j = i - 1; i >= 0; i--) {
    if (a - K <= As[j] && As[j] <= a && !lf) {
      l = subsolve(j) + 1;
    } else if (a <= As[j] && As[j] <= a + K && !rf) {
      r = subsolve(j) + 1;
    }
    if (lf && rf) break;
  }
  memo[i] = l > r ? l : r;
  return memo[i];
}
int solve() {
  for (int i = 0; i < N; i++) {
    memo[i] = -1;
  }
  int m = 0;
  for (int i = 0; i < N; i++) {
    m = m > subsolve(i) ? m : subsolve(i);
  }
  return m;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    cin >> As[i];
  }
  cout << solve() << "\n";
}
