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

public class A {
    DeluxeScanner in = new DeluxeScanner(null);
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);
    int n, d;
    int[] x;
    final int INF = Integer.MAX_VALUE >> 1;

    void run() {
        n = in.nextInt();
        d = in.nextInt();
        x = in.nextIntArray(n);
        Arrays.sort(x);
        int cnt = INF;
        for (int i = 0; i < n; i++) {
            for (int j = n - 1; j > i; j--) {
                if (x[j] - x[i] <= d) {
                    cnt = Math.min(cnt, n - j + i - 1);
                    break;
                }
            }
        }
        out.print(cnt);
        out.close();
    }

    public static void main(String[] args) {
        new A().run();
    }

    static class DeluxeScanner {
        BufferedReader br;
        StringTokenizer st;

        DeluxeScanner(String filename) {
            if (filename != null)
                try {
                    br = new BufferedReader(new FileReader(filename));
                }
                catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            else
                br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        char[] nextCharArray(int n) {
            char[] g = new char[n];
            g = next().toCharArray();
            return g;
        }

        char[][] nextChar2DArray(int n, int m) {
            char[][] g = new char[n][m];
            for (int i = 0; i < n; i++)
                g[i] = nextCharArray(m);
            return g;
        }

        double[] nextDoubleArray(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++)
                a[i] = nextDouble();
            return a;
        }

        double[][] nextDouble2DArray(int n, int m) {
            double[][] a = new double[n][m];
            for (int i = 0; i < n; i++)
                a[i] = nextDoubleArray(m);
            return a;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        int[][] nextInt2DArray(int n, int m) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++)
                a[i] = nextIntArray(m);
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        long[][] nextLong2DArray(int n, int m) {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++)
                a[i] = nextLongArray(m);
            return a;
        }
    }

    void exit() {
        out.close();
        System.exit(0);
    }
}