import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class test{
	
    public static void main(String... args) throws NumberFormatException, IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int d=Integer.parseInt(st.nextToken());
        int[] a=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++) {
        	a[i]=Integer.parseInt(st.nextToken());
        }
        Arrays.sort(a);
        int start=0;
        int ans=0;
        for(int i=0;i<n;i++) {
        	if(a[i]-a[start]<=d) {
        		ans=ans>i-start?ans:i-start+1;
        	}
        	else {
        		while(a[i]-a[start]>d) {
        			start++;
        		}
        		ans=ans>i-start?ans:i-start+1;
        	}
        }
        System.out.println(n-ans);
    } 
}
