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

public class Main {
    public static void main(String arg[]) {
        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();
        }

        sort(arr, 0, arr.length - 1);
        int ans = find(arr, d);

        System.out.println(ans);
    }

    static int find(int[] arr, int d) {
        if(arr.length == 1) {
            return 0;
        }

        int max = 0;
        for(int i = 0; i < arr.length; i++) {
            for(int j = i + 1; j < arr.length; j++) {
                int diameter = arr[j] - arr[i];
                if(diameter > d) {
                    break;
                }
                max = Math.max(max, j - i + 1);
            }
        }
        return arr.length - max;
    }

    static void sort(int[] arr, int left, int right) {
        if(left < right) {
            int length = right - left + 1;

            // Randomly pick a value from the given range of array
            Random generator = new Random();
            int randomIndex = generator.nextInt(length);
            int randomValue = arr[left + randomIndex];

            int[] temp = new int[length];
            int m = 0, n = 0;
            for(int i = left; i <= right; i++) {
                if(arr[i] < randomValue) {
                    temp[m] = arr[i];
                    m++;
                }
                if(arr[i] > randomValue){
                    temp[length - 1 - n] = arr[i];
                    n++;
                }
            }

            for(int i = m; i <= length - 1 - n; i++) {
                temp[i] = randomValue;
            }

            int indexOfLeftUpper = left + m - 1;
            int indexOfRightLower = right - n + 1;

            // Copy temp to array
            for(int i = left; i <= right; i++) {
                arr[i] = temp[i - left];
            }

            sort(arr, left, indexOfLeftUpper);
            sort(arr, indexOfRightLower, right);
        }
    }
}
