import java.util.*;
public class A{
       public static void main(String args[]){
              Scanner sc = new Scanner(System.in);
              int n = sc.nextInt();
              int k = sc.nextInt();
              int a[] = new int[n];
              for(int i = 0; i < n; i++)
                     a[i] = sc.nextInt();
              Arrays.sort(a);
             int b[] = new int[n];
             TreeSet<int[]> trie = new TreeSet<int[]>(new Comparator<int[]>(){
                    public int compare(int i1[], int i2[]){
                           return i1[0] - i2[0];
                    }
             });
             trie.add(new int[]{0, 0});
             for(int i = 1; i < n; i++){
                    b[i] = a[i] - a[0];
                    trie.add(new int[]{b[i], i});
             }
             int min = Integer.MAX_VALUE;
             for(int i = 0; i < n; i++){
                    int curr[] = trie.ceiling(new int[]{b[i] - k, 0});
                    if(b[i] - curr[0] <= k){
                          // System.out.println(i + " " + curr[1] + " " + (b[i] - k));
                            min = Math.min(min, n - (i - curr[1] + 1));
                    }
             }
              System.out.println(min);
       }
}