import java.util.*;
public class A {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        
        int i = 0;
        int min = n-1;
        for (int j = 0; j < n; j++) {
            while (arr[i] + d < arr[j]) i++;
            
            int total = j - i + 1;
//            System.out.println(i + " "+j+ " "+total);
            min = Math.min(min, n-total);
        }
        System.out.println(min);
            
        
    }
}
