import java.util.*;
import java.io.*;
import java.lang.*;

public class Solution {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);
    StringTokenizer st = new StringTokenizer("");

    String next() {
        if (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {

            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    public static void main(String[] args) {
        new Solution().solve();
    }

    void solve() {
        int t = 1;
        // t = nextInt();
        for (int tt = 0; tt < t; tt++) {
            int n = nextInt(), d = nextInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            Arrays.sort(arr);
            int flag = -1;
            for (int k = n; k >= 0; k--) {
                for (int i = 0; i + k - 1 < n; i++) {
                    int start = arr[i], end = arr[i + k - 1];
                    if (end - start <= d) {
                        flag = k;
                        break;
                    }
                }
                if (flag != -1)
                    break;
            }
            out.println(n - flag);
        }
        out.close();
    }
}
