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

public class A {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] ree = in.readLine().split("\\s++");
		int nn = Integer.parseInt(ree[0]);
		int d = Integer.parseInt(ree[1]);
		int[] arr = new int[101];
		ree = in.readLine().split("\\s++");
		int min = 200;
		int max = -100;
		for(int i = 0; i < nn; i++) {
			int n = Integer.parseInt(ree[i]);
			if(n < min) min = n;
			if(n > max) max = n;
			arr[n]++;
		}
		int removeMin = 0;
		int removeMax = 0;
		for(int i = 1; i < 100; i++) {
			if(min + d < i) removeMin += arr[i];
			if(max - d > i) removeMax += arr[i];
		}
		System.out.println(removeMin < removeMax ? removeMin : removeMax);
	}
}