import java.util.Arrays;
import java.util.Scanner;

public class A940PointsOnTheLine {
	
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int listLength = sc.nextInt();
		int tarRange   = sc.nextInt();
	
		int[] ist = new int[listLength];
		
		for (int i = 0; i < listLength; i++ ) {
			ist[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(ist);

		// Initiating variables -^-^-^-^-^-
		if (listLength == 1) {
			System.out.println(0);
		} else {
			int lowest = listLength;
			for (int a = 0; a < listLength; a++) {
				int low = 0;
				int iter = 0;
				for (int b = 1; b < listLength - a; b++) {
					if (ist[listLength - b] - ist[a] <= tarRange ) {
						low =  a + iter;
						if (a == listLength - b) low = listLength -1;

						if (low < lowest) lowest = low;
						break;
					} else {
						iter += 1;
					}
				}
			}
			System.out.println(lowest);
		}
	}
}
