import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();

            if (n <= d) {
                out.println("0");
                return;
            }

            ArrayList<Integer> a = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                a.add(in.nextInt());
            }

            Collections.sort(a);
            int max = 0;
            for (int i = 0; i < n - 1; i++) {
                int ci = a.get(i);
                for (int j = i + 1; j < n; j++) {
                    int cj = a.get(j);
                    if (cj - ci > d) {
                        if (j - i - 1 > max) max = j - i - 1;
                        break;
                    } else if (j == n - 1) {
                        if (j - i > max) max = j - i;
                    }
                }
            }

            out.print(n - max - 1);
        }

    }
}

