import java.util.Scanner;

public class Maon {
    public static void main(String [] args){
        Scanner sc  = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int nums[]  = new  int[n];
        for (int i = 0; i < n ;i++){
            nums[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n - 1; j++){
                if (nums[j] > nums[j + 1]){
                    int buf = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = buf;
                }
            }
        }
        int[] res = new int[n];
        for (int y : res) y = -1;
        int left = 0;
        for (int j = 0, l = 0; j < n; j++){
            if ((nums[j] - nums[left]) > d){
                res[l++] = j - left;
                left++;
                j = left;
            } else if (j == n - 1){
                res[l] = n - left;
            }
        }
        int max = 0;
        for (int k = 0; k < n; k++){
            if (max < res[k]) max = res[k];
        }
        System.out.println(n - max);
    }
}
