import java.util.*;
import java.io.*;
import java.text.*;
public class TC{
    static final long MOD = (long)1e9+7;
    static int MAX = (int)1e6+1;
    static double eps = 1e-9;
    static FastReader in;

    public static void main(String[] args) throws Exception{
        in = new FastReader();
        StringBuilder out = new StringBuilder("");
        int[] x = new int[101];
        int N = ni(), D = ni();
        for(int i = 0; i< N; i++)x[ni()]++;
        for(int i = 1; i<= 100; i++)x[i]+=x[i-1];
        int ans = N;
        for(int i = 1; i+D<=100;i++){
            ans = Math.min(ans, N-(x[i+D]-x[i-1]));
        }
        System.out.print(ans);
    }
    
    static boolean valid(int x){
        return x>=0 && x<64;
    }
    
    static boolean adjacent(int x1, int y1, int x2, int y2){
        return (Math.max(Math.abs(x1-x2), Math.abs(y1-y2))<2);
    }
    
    static long mod(long m){
        return (m%MOD+MOD)%MOD;
    }
    
    static void p(Object o){
        System.out.print(o);
    }
    
    static void pn(Object o){
        System.out.println(o);
    }
    
    static String n(){
        return in.next();
    }
    
    static String nln(){
        return in.nextLine();
    }
    
    static int ni(){
        return Integer.parseInt(in.next());
    }
    
    static long nl(){
            return Long.parseLong(in.next());
    }
    
    static double nd(){
        return Double.parseDouble(in.next());
    }
    
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }
 
        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
} 