import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
	private static int N, D;
	private static int result = Integer.MAX_VALUE;
	private static ArrayList<Integer> list = new ArrayList<Integer>();

	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(f.readLine());
		N = Integer.parseInt(st.nextToken());
		D = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(f.readLine());
		for (int i = 0; i < N; i++) {
			list.add(Integer.parseInt(st.nextToken()));
		}
		Collections.sort(list);
		for (int i = 0; i < N; i++) {
			int left = list.get(0);
			for (int j = i; j < N; j++) {
				int right = list.get(j);
				if (right - left <= D) {
					result = Math.min(result, N - (j - i + 1));
				}
			}
		}
		System.out.println(result);
	}
}