import java.util.Arrays;
import java.util.Scanner;


public class PointsOnTheLine {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[] = new int[n];
		for(int i=0;i<n;i++)
			arr[i] = sc.nextInt();
		Arrays.sort(arr);
		int min = n-1;
		for(int i=0;i<n;i++){
			int c = 0;
			int j;
			for(j=i+1;j<n;j++){
				if(arr[j]-arr[i] >d)
					break;
			}
			c = i+(n-j);
			if(min>c)
				min = c;
		}
		System.out.println(min);
	}

}
