
import java.util.ArrayList;
import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		int d=scanner.nextInt();
		ArrayList<Integer> list=new ArrayList<>();
		for(int i=0;i<n;i++) {
			list.add(scanner.nextInt());
		}
		int neshan=0;
		int maxlen=0;
		list.sort(null);
		for(int i=0;i<n;i++) {
			for(int j=i+1;j<n;j++) {
				if(list.get(j)-list.get(i)>d) {
					neshan=j-1;
					break;
				}
				else {
					if(j==n-1) {
						neshan=n-1;
					}
				}
			}
			if(neshan-i+1>maxlen)
				maxlen=neshan-i+1;
		}
		System.out.println(n-maxlen);
		scanner.close();
	}
}
