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

public class TaskA {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solve solve = new Solve();
        solve.solve(in, out);
        out.close();
    }

    private static class Solve {
        private final static long MOD = 1000000007L;

        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int[] f = new int[n];
            for (int i = 0; i < n; i++) {
                f[i] = in.nextInt();
            }
            Arrays.sort(f);
            int ans = 0;
            for (int left = 0; left < n; left++) {
                for (int right = left; right < n; right++) {
                    if (f[right] - f[left] <= d) {
                        ans = StrictMath.max(ans, right - left + 1);
                    }
                }
            }
            out.print(n - ans);
        }

        private long pow(long n, long p) {
            if (p == 0) return 1;
            long x = pow(n, p / 2);
            x = (x * x) % MOD;
            if (p % 2 == 1) x = (x * n) % MOD;
            return x;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
