/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package CP;

/**
 *
 * @author Divyam Anshumaan
 */
import java.util.Scanner;
import java.util.Arrays;

public class g4g_save_gotham {
    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);
        //System.out.println(arr[0]);
        int d = arr[N-1] - arr[0];
        int i = 0;
        int j = 0;
        while(d>D){
           
          if(arr[N-2-i]-arr[j]>=arr[N-i-1]-arr[j+1]){
              j++;
              d = arr[N-i-1]-arr[j];
          }
          else{
              i++;
              d = arr[N-1-i]-arr[j];
          }
           
        }
        if(i==0)
            System.out.println(0);
        else
            System.out.println(i+j);
    }
}
