import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class _940A {

    private static void solve(Scanner scan, PrintWriter pw) {
        int n = scan.nextInt(), d = scan.nextInt();

        int[] points = new int[n];

        for(int i = 0; i < n; i++) {
            points[i] = scan.nextInt();
        }

        Arrays.sort(points);

        int c1 = 0, c2 = 0;

        int ans = n-1;

        while (c2 < n-1) {
            while(c2 < n-1 && points[c2+1] - points[c1] <= d) {
                c2++;
            }

            ans = Math.min(ans, c1 + n - 1 - c2);

            c1++;
        }

        pw.println(ans);
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024 * 64));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 1024 * 64));
        solve(scan, pw);
        pw.flush();
    }

}