import java.util.Scanner;
import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.Collections;
import java.util.ArrayList;
import java.lang.Math;

public class A940B{

  public static boolean checkInRange(int number1, int number2 , int diameter){

    boolean check = false;
    int abs = number1 - number2;

    if (number1 - number2 < 0){
      abs = number2 - number1 ;
    }

    if (abs <=diameter){
      check = true;

    }
    return check;
  }




  public static void main(String[] args){


    Scanner inp = new Scanner(System.in);

    String inf = inp.nextLine();
    List<Integer> infs = Arrays.stream(inf.split(" ")).map(Integer::parseInt).collect(Collectors.toList());
    String numb = inp.nextLine();
    List<Integer> numbs = Arrays.stream(numb.split(" ")).map(Integer::parseInt).collect(Collectors.toList());

    Collections.sort(numbs);

    int n = infs.get(0);
    int diameter = infs.get(1);


    int vmax = 0 ;
    int j = 1 ;
    for (int i = 0 ; i < n ; i ++){

      while(j < n && checkInRange(numbs.get(i), numbs.get(j), diameter)){
        j += 1 ;
      }
      
      vmax =  Math.max(vmax, j - i) ;
      if (j == i){
        j = i + 2 ;
      }
    }

    System.out.println(n - vmax);

  }
}
