import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;
public class Main 
{ 
    public static void main(String[] args) throws IOException 
    { 
  
        Scanner input = new Scanner(System.in);
        
        while(input.hasNext()){
            int[] l=new int[input.nextInt()];
            int ind=0;
            int d=input.nextInt();
            while(ind<l.length){
                l[ind]=input.nextInt();
                ind++;
            }
            System.out.println(s(l,d));
        }
        }
 
    public static int s(int[] l, int d){ 
        Arrays.sort(l);
        int min=Integer.MAX_VALUE;
        for(int i=0;i<l.length;i++){
            for(int j=l.length-1;j>=0;j--){
                if(l[j]-l[i]<=d){
                    min=Math.min(i+l.length-1-j, min);
                }
            }
        }
        return min;
                }
            
        

 
} 