import java.util.Arrays;
import java.util.Scanner;

public class codeforces1 {

    static int getMinRemoval(int[] arr, int n, int d) {

        Arrays.sort(arr);
        int maxInterval = 0;
        for (int i = 0; i < n; i++) {
            for (int j = n - 1; j >= i; j--) {
                if (arr[j] - arr[i] <= d) {
                    maxInterval = Math.max(maxInterval, j - i);
                }
            }
        }
        return n - maxInterval - 1;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner sc = new Scanner(System.in);
        int n;
        int d;

        n = sc.nextInt();
        d = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        System.out.println(getMinRemoval(arr, n, d));
        // return getMinRemoval(arr, n, d);

    }

}
