import java.util.Arrays;
import java.util.Scanner;

public class PointsonaLine {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int d = input.nextInt();
		
		int[] arr = new int[n];
		for(int i=0; i<n;i++)arr[i] = input.nextInt();
		Arrays.sort(arr);
		int min = Integer.MAX_VALUE;
		int i=0;
		int j=1;
		while(j<n && arr[j]-arr[i]<=d)j++;
		if(j==n){
			System.out.println(0);
			return;
		}
		  j--;
		 min = j-i+1;
	//	 System.out.println(min);
		while(i+1<n && j<n){
			i++;
			while( j<n && arr[j]-arr[i]<=d)j++;
			j--;
		   
		    if(j-i+1>min){
			   min = j-i+1;
		   }
		}
		System.out.println(n-min);
				
		
	}

}
