
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

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

        int array[] = new int[n];


        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }
        Arrays.sort(array);
        int counter = 1;
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            int j = i;
            while (j < n && array[j] - array[i] <= d)
                j++;
            min = Math.min(min, n - (j - i));
        }
        System.out.println(min);

    }
}
