// Arup Guha
// 5/11/2016
// Solution to USACO 2016 Bronze April Problem: Diamond Collector

import java.util.*;
import java.io.*;

public class diamond {

	public static void main(String[] args) throws Exception {

		// Read in data.
		BufferedReader stdin = new BufferedReader(new FileReader("diamond.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int k = Integer.parseInt(tok.nextToken());
        int[] vals = new int[n];
        for (int i=0; i<n; i++)
            vals[i] = Integer.parseInt(stdin.readLine().trim());

		// Sort the data.
		Arrays.sort(vals);

		int res = 0;
		int low = 0, high = 0;

		// Sweep through the array with two pointers.
		while (high < n) {

            // Valid interval check if it's the best and extend high.
            if (vals[high] - vals[low] <= k) {
                res = Math.max(res, high-low+1);
                high++;
            }

            // Must move low to find new intervals.
            else
                low++;
		}

		// Write result.
		PrintWriter out = new PrintWriter(new FileWriter("diamond.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}
