import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.InputMismatchException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nirav
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scan in = new Scan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemAPointsOnTheLine solver = new ProblemAPointsOnTheLine();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemAPointsOnTheLine {
        public void solve(int testNumber, Scan in, PrintWriter out) {
            int n = in.scanInt();
            int d = in.scanInt();
            ArrayList<Integer> list = new ArrayList<>();
            int a[] = new int[105];
            for (int i = 0; i < n; i++) {
                int tmep = in.scanInt();
                if (!list.contains(tmep)) {
                    list.add(tmep);
                }
                a[tmep]++;
            }
            Collections.sort(list);
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < list.size(); i++) {
                int temp = 0;
                for (int j = i; j < list.size(); j++) {
                    if ((list.get(j) - list.get(i)) > d) {
                        for (int k = list.get(j); k < a.length; k++) {
                            if (k < a.length) {
                                if (a[k] != 0) {
//                                out.println(list.get(i)+" "+list.get(j)+" "+k);
                                }
                                temp += a[k];
                            }
                        }
                        for (int k = 0; k < list.get(i); k++) {
                            if (k < list.get(i)) {
                                if (a[k] != 0) {
//                                out.println(k);
                                }
                                temp += a[k];
                            }
                        }
                        if (temp < ans) {
                            ans = temp;
                        }
//                    out.println("temp "+temp);
                        break;
                    }

                }
            }
            if (ans == Integer.MAX_VALUE) {
                ans = 0;
            }
            out.println(ans);


        }

    }

    static class Scan {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;

        public Scan() {
            in = System.in;
        }

        public Scan(InputStream inputStream) {
            in = inputStream;
        }

        public int scan() {
            if (total < 0) {
                return 0;
            }
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    System.out.println(e);
                }
                if (total <= 0)
                    return -1;

            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n))
                n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                } else throw new InputMismatchException();
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
                return true;
            return false;
        }

    }
}

