import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Nowrin on 24-Feb-18.
 */
public class cf940a {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n,d;
        n = in.nextInt();
        d = in.nextInt();
        int ar[] = new int[n];

        for (int i = 0; i <n ; i++) ar[i]=in.nextInt();
        Arrays.sort(ar);
        if(n==1) System.out.println(0);
        else {
            int j = n - 1, c = 0, max = 0, p;

            for (int i = 0; i < n - 1; i++) {
                for (j = n - 1; j >= i; j--) {
                    c = Math.abs(ar[j] - ar[i]);
                    if (c <= d) {
                        p = j - i + 1;
                        if (p > max) max = p;
                        break;
                    }
                }
            }
            //  if(max==0)max++;
            System.out.println(n - max);
        }
       /* for (int i = 0; i < n; i++) {
            p = Math.abs(ar[i]-ar[j]);
            if(p<=d)break;
            else {

            }
        }*/

    }
}
