import java.io.*;
import java.util.*;
import java.util.regex.*;
public class vk18
{
    public static void main(String[]stp) throws Exception
    {
    	Scanner scan=new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String []s;
        int n=scan.nextInt(),d=scan.nextInt(),min=Integer.MAX_VALUE,count=0,i,j;
        int a[]=new int[n];
        for(i=0;i<n;i++) a[i]=scan.nextInt();
        Arrays.sort(a);
        for(i=0;i<n;i++)
        {
        	count=0;
        	for(j=i;j<n;j++)
        	{
        		if(a[j]-a[i] <= d) {count++; }
        		else	{min=Math.min(min,(n-count)); break; }
        	}
        	min=Math.min(min,(n-count));
        }
        min=Math.min(min,(n-count));
        System.out.println(min);
    }
}