import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n = sc.nextInt();
        int d = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            list.add(a);
        }
        int answer = n;
        Collections.sort(list);
        for (int i = 0; i < n; i++) {
            for (int j = n - 1; j > i; j--) {
                if (list.get(j) - list.get(i) <= d) {
                    answer = Math.min(answer, n - 1 - j + i);
                    break;
                }
            }
        }
        System.out.println(answer);
    }


}
