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


public class A940{
	public static void main(String args[])throws IOException{
		Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n=sc.nextInt();
		int d=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		Arrays.sort(a);
		if(n==1){

		System.out.println(0);
		return ;
		}
		int ans=n;
		for(int i=0;i<n-1;i++){
			int beg=i;
			int end=n-1;
			int mid=0;
			while(beg<=end){
				 mid=beg+(end-beg)/2;
				if(a[mid]-a[i]<=d){
					if(mid==n-1){
						break;
					}
					else if(a[mid+1]-a[i]>d){
						break;
					}
					else beg=mid+1;
				}
				if(a[mid]-a[i]>d){
					end=mid-1;
				}
			}
			if(beg<=end)
				ans=Math.min(ans,n-mid+i-1);
		}

		System.out.println(ans);
	}
}