import java.util.*;
import java.io.*;

public class A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		int N = sc.nextInt(), D = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = sc.nextInt();
		Arrays.sort(A);
		
		int ans = Integer.MAX_VALUE;
		for (int l = 0; l < N; l++) {
			for (int r = l+1; r < N; r++) {
				if (A[r] - A[l] <= D) {
					ans = Math.min(ans, N - (r - l + 1));
				}
			}
		}
		
		out.println(ans < Integer.MAX_VALUE ? ans : N-1);

		sc.close();
		out.close();
	}
}
