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);
		int i=0,j=n-1;
		if(n==1){

		System.out.println(0);
		return ;
		}
		while(i<j&&a[j]-a[i]>d){
			if(a[j]-a[i+1]<=d){
				i++;
			}
			else if(a[j-1]-a[i]<=d){
				j--;
			}
			else{
				i++;j--;
			}
		}

		System.out.println(Math.min(i+n-j-1,n));
	}
}