
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int x, y;
		x = sc.nextInt();
		y = sc.nextInt();
		int[] arr = new int[x];
		for(int i = 0;i < x;i++)
			arr[i] = sc.nextInt();
		Arrays.sort(arr);
		int points = 1002;
		for(int i = 0;i < x - 1;i++) {
			int j = i + 1;
			while(j < x && arr[j] - arr[i] <= y)
				j++;
			points = Math.min(points, j == x || j == i? points : x - (j - i));
		}
		System.out.println(points == 1002 ? 0 : points);
	}
}
