
import java.io.*;
import java.util.*;

public class Points {

    void solve() throws IOException {
        int n = nextInt();
        int d = nextInt();
        int x[] = new int[n];

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

        int minDeleted = 1000000000;
        Arrays.sort(x);
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if(x[j] - x[i] <= d) {
                    int curDeleted = n - (j - i + 1);
                    if(curDeleted < minDeleted) {
                        minDeleted = curDeleted;
                    }
                }
            }
        }
        System.out.println(minDeleted);
    }

    public static void main(String[] args) throws IOException {
        new Points().run();
    }

    void run() throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.in"));
        tokenizer = null;
        out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.out"));
        solve();
        reader.close();
        out.flush();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}