import java.util.*;

public class E {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int d = scanner.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(scanner.nextInt());
		}
		Collections.sort(list);
		int result = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				if (list.get(j) - list.get(i) <= d) {
					result = Math.max(result, j - i + 1);
				} else
					break;
			}
		}
		System.out.println(n - result);
	}

}
