import java.io.*;
import java.util.*;
import java.lang.*;

public class Rextester{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        StringTokenizer st1 = new StringTokenizer(br.readLine());
        int n = new Integer(st.nextToken());
        int d = new Integer(st.nextToken());
        br.close();
        int[] array = new int[n];
        for(int i=0;i<n;i++){
            array[i]=new Integer(st1.nextToken());
        }
        Arrays.sort(array);
        int beg=0,end=0;
        for(int i=0;i<n;i++){
            if(array[n-1]-array[i]<=d){
                beg = i;
                break;
            }
        }
        for(int i=n-1;i>=0;i--){
            if(array[i]-array[0]<=d){
                end = n-i-1;
                break;
            }
        }
        System.out.println(Math.min(beg,end));
    }
}
            
            
            
        