import java.util.*;
import java.math.*;

public class Main
{	
	
    public static void main(String args[])
    {
     
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int d=s.nextInt();
        int [] arr=new int[n];
        for(int i=0;i<n;i++) {
        	arr[i]=s.nextInt();
        }
        Arrays.sort(arr);
        
        int count1=1;
       
        int o=0;
        while(o<n) {
        	int count=1;
        	 int ans=0;
             int j=o+1;
        while((j)<n) {
        	ans=arr[j]-arr[o];
        	
        	if(ans<=d) {
        	j++;
        	count++;
        //	System.out.println(j);
        	}
        	if(ans>d||j==(n)){
       		// System.out.println("hello");
        		if(count>count1) {
        			count1=count;
        		}
        	//	 System.out.println(count);
        		break;
        	}
        }
       
        o++;
        }
        
     // System.out.println(count);
       // System.out.println(count1);
        System.out.println(n-count1);
        
        
    }
}
