import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
    private static StringBuilder sb = new StringBuilder();
    private static void s(String s){
        System.out.print(s);
    }
    private static void s(Double s){
        System.out.print(s);
    }
    private static void s(char s){
        System.out.print(s);
    }
    private static void sn(String s){
        System.out.println(s);
    }
    private static void sn(Boolean s){
        System.out.println(s);
    }
    private static void sn(long s){
        System.out.println(s);
    }
    private static void sn(Double s){
        System.out.println(s);
    }
    private static void sn(String s, Object o){
        sb.append(s+"\n");
    }
    private static void sn(long s, Object o){
        sb.append(s+"\n");
    }
    private static void sn(boolean s, Object o){
        sb.append(s+"\n");
    }
    private static void pr() throws Exception{
        BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
        bw.write(sb.toString());
        bw.flush();
    }
    static class Reader{
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[51]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    private static boolean isPrime(Integer ii){
        return new BigInteger(ii+"").isProbablePrime(1);
    }
    private static boolean isDigit(int ii){
        return Character.isDigit((char)ii);
    }
    private static long fact(int f){
        if(f==0){
            return 1;
        }
        return (long)f * (long)fact(f-1);
    }
    /*static int ar[] = new int[1000000];
    static {
        Arrays.fill(ar, 1000070);
        ar[0]=0;
        int arrr[] = new int[]{2,3,5,7};
        for(int i=0;i<4;i++){
            for(int ii=0;ii<1000000;ii++){
                if(ii>=arrr[i]){
                    ar[ii] = Math.min(ar[ii], 1+ar[ii-arrr[i]]);
                }
            }
        }
    }*/
    /*static{
        Arrays.fill(prime, true);
        for(int p = 2; p*p <=1000070; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == true)
            {
                // Update all multiples of p
                for(int i = p*2; i <= 1000070; i += p)
                    prime[i] = false;
            }
        }
        int nc = 0;
        for(int p = 2; p <=1000070; p++)
        {
            if(prime[p] == true && prime[(p+1)/2] == true)
            {
                prr[p]+=nc+1;
                nc = prr[p];
            }
        }
    }*/
    private static Reader r = new Reader();
    private static int ni() throws Exception{
        return r.nextInt();
    }
    private static String ns() throws Exception{
            return r.readLine();
        }
    private static long nl() throws Exception{
        return r.nextLong();
    }
    private static int[] na(int a) throws Exception{
        int arr[] = new int[a];
        for(int i=0;i<a;i++){
            arr[i] = r.nextInt();
        }
        return arr;
    }
    private static long[] nal(int a) throws Exception{
        long arr[] = new long[a];
        for(int i=0;i<a;i++){
            arr[i] = r.nextLong();
        }
        return arr;
    }
    private static boolean isSquare(int a){
        double sqt = Math.sqrt(a);
        return (int)sqt == sqt;
    }
    private static int lSquare(int a){
        double sqt = Math.sqrt(a);
        return (int)sqt * (int) sqt;
    }
    private static int rSquare(int a){
        double sqt = Math.sqrt(a);
        return (int)Math.ceil(sqt) * (int)Math.ceil(sqt);
    }
    private static int parent[] = new int[200005];
    private static boolean visit[] = new boolean[200005];
    private static void init(){
    	for(int i=0;i<200005;i++){
    		parent[i] = 0;
    	}
    	for(int i=0;i<200005;i++){
    		visit[i] = false;
    	}
    }
	private static void bfs(int size[], int ans, List[] list, int start, int end, Queue<Integer> q){
    	while(!q.isEmpty()){
    		int temp = q.remove();
    		visit[temp] = true;
    		for(int i=0;i<list[temp].size();i++){
    			if(!visit[(int)list[temp].get(i)] && end == (int)list[temp].get(i)){
    				parent[end] = temp;
    				visit[(int)list[temp].get(i)] = true;
    				return;
    			}
    			if(!visit[(int)list[temp].get(i)]){
    				q.add((int)list[temp].get(i));
    				parent[(int)list[temp].get(i)] = temp;
    			}
    		}
    	}
    }
    public static int dfs(List []list, int arr[], int k, int i, int ii){
        if(i==1 && arr[i]!=arr[ii]){
            return -1;
        }
        if(arr[i] == arr[ii]){
            k--;
            if(k==0){
                return i;
            }
        }
        for(int j=0;j<list[i].size();j++){
            return dfs(list, arr, k, (int)list[i].get(j), ii);
        }
        return -1;
        }
        private static boolean isPerfectSquare(int n){
            if((int)Math.sqrt(n) * (int)Math.sqrt(n) == n){
                return true;
            }
            return false;
        }
        static void printSubsets(char set[])
    {
        int n = set.length;
 
        // Run a loop for printing all 2^n
        // subsets one by obe
        for (int i = 0; i < (1<<n); i++)
        {
            System.out.print("{ ");
 
            // Print current subset
            for (int j = 0; j < n; j++)
 
                // (1<<j) is a number with jth bit 1
                // so when we 'and' them with the
                // subset number we get which numbers
                // are present in the subset and which
                // are not
                if ((i & (1 << j)) > 0)
                    System.out.print(set[j] + " ");
 
            System.out.println("}");
        }
    }
    //segment tree impl
    
    static class Tree{
        int sum;
        int maxl;
        int maxr;
        int maxi;
        public String toString(){
            return sum+" "+maxl+" "+maxr+" "+maxi;
        }
    }
    
    private static Tree combine(Tree left, Tree right)
    {
        Tree t = new Tree();
        t.sum = left.sum+right.sum;
        t.maxl = Math.max(left.maxl, left.sum+right.maxl);
        t.maxr = Math.max(right.sum+left.maxr, right.maxr);
        t.maxi = Math.max(right.maxl+left.maxr,Math.max(left.maxi, right.maxi));
        return t;
    }
    
    private static void build(int n, Tree tree[]){
        for(int i=n-1;i>0;i--){
            tree[i] = combine(tree[i<<1], tree[i<<1|1]);
        }
    }
    
    private static Tree queryRec(int node , int start , int end , int x , int y, Tree tree[]){
        if(start == x && end == y) return tree[node];
        int l = node<<1 ;
    int r = node<<1|1;

    int mid = (start + end )>>1;

    if(y <= mid ) return queryRec(l,start,mid,x,y,tree); // whole side is in left

    else if( x > mid ) return queryRec(r,mid+1,end,x,y,tree) ; // whole side is in right

    else
    {
        return combine( queryRec(l,start,mid,x,mid,tree) , queryRec(r,mid+1,end,mid+1,y,tree)  ) ; // split in two side so merging
    }
    }
    
    
    private static Tree query(int n, int l, int r, Tree tree[]){
        Tree tl = tree[n], tr = tree[n];
        for(l=l+n,r=r+n;l<r;l/=2,r/=2){
            if(l%2!=0) tl=tree[l++];//combine(tl, );
            if(r%2!=0) tr=tree[--r];//combine(tr, tree[--r]);
        }
        return combine(tl, tr);
    }
	public static void main (String[] args) throws Exception{
	    int n = ni();
	    int d = ni();
	    int arr[]  = na(n);
	    Arrays.sort(arr);
	    if((arr[n-1]-arr[0])<=d){
	        sn(0);
	        return;
	    }
	    int min = 1000;
	    for(int i=0;i<n;i++){
	        int p = i;
	        int j=n-1;  
	            while(arr[j]-arr[i]>d){
	                j--;
	            }
	            p+=n-j-1;
	            min  = Math.min(p, min);
	        
	    }
	    sn(min);
	}
}