import java.util.*;
public class main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n  = sc.nextInt();
		int d = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
	
		Arrays.sort(a);
		int cd = a[n-1] - a[0];
		int count=0;
		int left=0;
		int right = n-1;
		if(n == 1) {
			System.out.println(0);
		}
		else {
		while(cd>d) {
			
			if(left == right) {
				break;
			}
			
				if(a[right]-a[left+1] < a[right-1]-a[left]) {
					
					left++;
					cd = a[right] - a[left];
				}
				else {

					right--;
					cd = a[right] - a[left];
				}
				count++;
			
		}
		System.out.println(count);
		}
		
	}
	

}
