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

/**
 * 0da - 24.02.2018.
 */
public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int des = scanner.nextInt();


        int[] array = new int[n];

        for (int i = 0; i < n; i++) array[i] = scanner.nextInt();
        if (n == 1) {
            System.out.println(0);
            return;
        }

        Arrays.sort(array);
        int max = Integer.MIN_VALUE;

        for (int i = 0; i < n; i++) {
            int local = 0;
            for (int j = i; j < n; j++) {
                if (Math.abs(array[i] - array[j]) > des) break;
                else local++;
            }
            max = Math.max(max, local);
        }


        /*
        n, r = map(int, input().split())
        dots = list(map(int, input().split()))
        dots.sort()
        max = 0
        for num in range(len(dots)):
            local = 0
            for num2 in range(num, len(dots)):
                if abs(num - num2) <= r:
                    local += 1
                else:
                    break
            if local > max:
                max = local

        print(n - max)
        */

       /*
         for (int i = 0; i < n; i++) {
            int local = 0;
            for (int j = 0; j < n; j++)
                if (Math.abs(array[i] - array[j]) > des) local++;
            min = Math.min(local, min);
        }*/

        System.out.println(n - max);
    }
}
