import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int d = s.nextInt();
        int arr[] = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        int ans = n;
        for(int i = 0; i < n; i++){
            int start = i,end = n - 1,index = i;
            while(start <= end){
                int mid = (start + end)/2;
                if(arr[mid] <= arr[i] + d){
                    index = mid;
                    start = mid + 1;
                }
                else{
                    end = mid - 1;

                }
            }
            if(index > i){
                int rem = n - (index - i + 1);
                ans = Math.min(ans,rem);
            }
        }
        System.out.println(ans);
    }
}