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

public class Main
{

    public static void solve(FastScanner in, BufferedWriter out) throws IOException {
        int n = in.nextInt(), d = in.nextInt();
        int[] a = new int[101];

        for (int i = 0; i < n; i++) {
            a[in.nextInt()]++;
        }

        int maxInD = 0;
        for (int i = 1; i <= 100-d ; i++) {
            int temp = 0;
            for (int j = 0; j <= d ; j++) {
                temp += a[i+j];
            }
            maxInD = max(maxInD, temp);
        }

        out.append(String.valueOf(n-maxInD));
    }


    /**************** ENTER HERE   ********************/
    public static void main(String[] args) throws Exception
    {
        FastScanner fscan = new FastScanner(System.in);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        solve(fscan,bw);
        bw.close();
    }
}


class FastScanner {
    StringTokenizer st;
    BufferedReader br;

    public FastScanner(InputStream s) {
        br = new BufferedReader(new InputStreamReader(s));
    }

    public void nextIntArray(int[] a) throws IOException
    {
        for(int i =0;i<a.length;i++)
            a[i] = nextInt();
    }

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {
        return br.readLine();
    }
}