import java.util.Arrays;
import java.util.Scanner;

public class Codeforces {    
    public static void main(String[] args) {
        TaskA Solver = new TaskA();        
        Solver.Solve();        
    }       
    private static class TaskA {                
        private void Solve() {    
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int d = in.nextInt();
            int ar[] = new int [n];
            for (int i = 0; i < n; i++)
                ar[i] = in.nextInt();
            Arrays.sort(ar);
            int minDel = 1000;
            for (int i = 0; i < n; i++)
                for (int j = i; j < n; j++)                     
                    if (ar[j] - ar[i] <= d) 
                        minDel = Math.min(minDel, i + n - 1 - j);                                    
            System.out.println(minDel);
        }
    }
}