import java.util.*;
public class prob1
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d= scan.nextInt();
		Integer a[] = new Integer[n];
		for(int i=0;i<n;i++){
		    a[i] = scan.nextInt();
		}
		Arrays.sort(a);
		int max=0;
		for(int i=0;i<n;i++){
		    int p=0;
		    for(int j=i;j<n&&a[j]<=a[i]+d;j++){
		        p=p+1;
		    }
		    if(p>max){
		        max=p;
		    }
		    p=0;
		    for(int j=i;j>0&&a[j]>=a[i]-d;j--){
		        p=p+1;
		    }
		    if(p>max){
		        max=p;
		    }
		}
		System.out.println(n-max);
	}
}