// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF940A extends PrintWriter {
	CF940A() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF940A o = new CF940A(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[] aa = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = sc.nextInt();
		Arrays.sort(aa);
		int ans = n;
		for (int i = 0, j = 0; i < n; i++) {
			while (j < n && aa[j] - aa[i] <= d)
				j++;
			ans = Math.min(ans, n - j + i);
		}
		println(ans);
	}
}
