import java.util.*;
public class p1{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int count=0;
		int d=s.nextInt();
		int[] arr=new int[n];
		Vector<Integer> v=new Vector();
		for(int i=0;i<n;i++){
			v.add(s.nextInt());
		}
		Collections.sort(v);
		int ptr1=0,ptr2=n-1;
		Iterator<Integer> it=v.iterator();
		for(int i=0;i<n;i++){
			arr[i]=it.next();
		}
		while(true){
			if(arr[ptr2]-arr[ptr1]<=d){
				System.out.println(count);
				break;
			}
			else {
				count++;
				if(arr[0] == arr[1]){
					ptr2--;// by removing first element
				}
				else if (arr[ptr2]==arr[ptr2-1]){
					ptr1++;
				}
				else{
					ptr1++;
					if(arr[ptr2]-arr[ptr1]<=d){
						System.out.println(count);
						break;
					}
					ptr1--;
					ptr2--;
					if(arr[ptr2]-arr[ptr1]<=d){
						System.out.println(count);
						break;
					}
				}
			}
		}
	}
}