import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int[] s = new int[n];
            int[] a = new int[101];
            for (int i = 0; i < n; i++) {
                s[i] = in.nextInt();
                a[s[i]]++;
            }

            for (int i = 1; i <= 100; i++) {
                a[i] += a[i - 1];
            }

            Arrays.sort(s);
            int min = 120;
            for (int i = 0; i < n; i++) {
                int x = s[i];
                for (int l = 0; l <= d; l++) {
                    int inc = (a[x] - a[Math.max(x - l - 1, 0)]) + (a[Math.min(x + (d - l), 100)] - a[x]);
                    //out.println(x + " " + l + " " + inc);
                    min = Math.min(n - inc, min);
                }
            }
            out.print(min);
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

    }
}

