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

public class PointsOnTheLine {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer t = new StringTokenizer(in.readLine());
		int N = Integer.parseInt(t.nextToken());
		int D = Integer.parseInt(t.nextToken());
		t = new StringTokenizer(in.readLine());
		int[] a = new int[N];
		for(int i = 0; i < N; ++i) a[i] = Integer.parseInt(t.nextToken());
		Arrays.sort(a);
		int j = 0;
		int ans = N;
		for(int i = 0; i < N; ++i) {
			while(j < N && a[j] - a[i] <= D)
				j++;
			if(j == N) {
				ans = Math.min(ans, i);
				break;
			}
			j--;
			ans = Math.min(ans, N - (j - i + 1));
		}
		out.println(ans);
		in.close();
		out.close();
	}
}