
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import java.util.StringTokenizer;

public class Main
{

    public Main() throws IOException
    {

    }

    private void solve() throws IOException
    {
        int n = nextInt(), d = nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = nextInt();
        }
        int ans = n;
        for (int i = 0; i < n; i++)
        {
            int cnt = 0;
            for (int j = 0; j < n; j++)
            {
                if (a[j] >= a[i] && a[j] <= a[i] + d)
                {
                    cnt++;
                }
            }
            ans = Math.min(ans, n - cnt);
        }
        out.println(ans);
    }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);
    String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

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

    private void run() throws IOException
    {
        solve();
        out.close();
    }

}