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

public class a {

    static int[] x = new int[110];
    static int[] count = new int[110];

    public static void main(String[] args) {
        MyScanner scan = new MyScanner();
        int n = scan.nextInt();
        int d = scan.nextInt();
        for (int i = 0; i < n; ++ i) {
            x[i] = scan.nextInt();
        }

        Arrays.sort(x,0, n);

        for (int i = 0; i < n-1; ++ i) {
            for (int j = i+1; j < n; ++ j) {
                int dis = x[j] - x[i];
                int n_elem = j - i + 1;
                if (n_elem > count[dis]) {
                    count[dis] = n_elem;
                }
            }
        }

        int n_max = 0;
        for (int i = 0; i <= d; ++ i) {
            if (count[i] > n_max) {
                n_max = count[i];
            }
        }
        if (n_max == 0) {
            n_max = 1;
        }
        System.out.println(n - n_max);
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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();
        }

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

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

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

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

