import java.io.*;
import java.util.*;

public class Main
{  
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static class HM<T,Integer> extends HashMap<T,T> {};
    public static class AL<T> extends ArrayList<T> {};
    public static class HS<T> extends HashSet<T> {};
    
    public static void main(String[] args) throws IOException 
	{
		br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(br.readLine());
        int n=nxtInt(),m=nxtInt(),a[]=new int[n],dp[][]=new int[n][n];
        
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++) a[i]=nxtInt();
        Arrays.sort(a);
        int ans=n;
        for(int i=0;i<n;i++) for(int j=i;j<n;j++) if(Math.abs(a[j]-a[i])<=m) ans=Math.min(n-(j-i+1),ans);
        pr.println(ans);
        pr.flush();
        pr.close();
    }
    
    static int nxtInt(){
        return Integer.parseInt(st.nextToken());
    }
    
    static long nxtLong(){
        return Long.parseLong(st.nextToken());
    }
    
    static double nxtDoub(){
        return Double.parseDouble(st.nextToken());
    }
    
    static String nxt(){
        return st.nextToken();
    }
    
    static String nxtLn() throws IOException{
        return br.readLine();
    }
}