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

public final class Main {

    public static void main(String[] args) throws Exception {
        PrintWriter pw = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());

        if(n == 1){
            System.out.println(0);
            return;
        }

        st = new StringTokenizer(br.readLine());

        List<Integer> list = new ArrayList<>();

        while(st.hasMoreTokens()){
            int x = Integer.parseInt(st.nextToken());
            list.add(x);
        }

        Collections.sort(list);

        //sliding window in list such that window diameter is size <= d

        int minToRemove = Integer.MAX_VALUE;

        for(int i = 0; i<list.size(); i++){
            int leftVal = list.get(i);
            boolean found = false;
            for(int j = i+1; j<list.size(); j++){
                int rightVal = list.get(j);
                if(rightVal - leftVal > d){
                    //then valid is one to left of j
                    minToRemove = Math.min(minToRemove, list.size() - (j-i-i));
                    found = true;
                    break;
                }
            }
            if(!found){
                minToRemove = Math.min(minToRemove, i);
            }
        }
        pw.println(minToRemove);
        pw.close();
    }

}