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

public class Competitive_2 {
	
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n=in.nextInt(), d=in.nextInt();
		int arr[] = new int[n];
		
		for(int i=0; i<n; i++)
			arr[i] = in.nextInt();
		
		Arrays.sort(arr);
		
		int maxLen = 0;
		
		for(int i=0; i<n; i++){
			for(int j=n-1; j>=i; j--){
				if(arr[j]-arr[i]<=d){
					maxLen = Math.max(j-i+1, maxLen);
					break;
				}
			}
		}
		
		System.out.println(n-maxLen);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	
	
}
