import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		int [] arr=  new int[n];
		
		for (int i =0;i<n;i++)
			arr[i] = sc.nextInt();
		
		Arrays.sort(arr);
		
		int front = 0,back =n-1,count=0;
		
		while (front<back)
		{
			//System.out.println(arr[back]-arr[front]);
			if (arr[back]-arr[front]>d)
			{
				//System.out.println("ENtered");
				if (arr[back]-arr[front+1]<arr[back-1]-arr[front])
				{
					front++;
				}
				else
					back--;
				count++;
			}
			else
				break;
		}
		System.out.println(count);
		
		sc.close();

	}

}