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

public class Code940A {

	public static void main(String[] args) {
		Scanner read = new Scanner(System.in);
		try {
			int n = read.nextInt(), d = read.nextInt(), cont= 1, sum = 1, i = 0, j= 0;
			read.nextLine();
			int nd [] = new int [n];
			for(;i<n;i++) 
				nd[i]=read.nextInt(); 
			Arrays.sort(nd);
			for(i=0 ;i<n;i++) {	
				for(j=i+1;j<n && nd[j]-nd[i]<=d;j++) {
						cont++;
						sum = Math.max(cont, sum);
				}
				cont= 1;
			}
			
			System.out.print((n==1)?0:n-sum);		
			
		}catch(Exception e) {
			read.close();
		}
	}
}