import java.text.*;
import java.util.*;

public class CodeForces5 {

		public static void main(String [] args)
		{
			
			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int arr[] = new int [n];
			
			int d = sc.nextInt();
			
			for(int i = 0 ; i < n ; i++)
				arr[i] = sc.nextInt();
			
			Arrays.sort(arr);
			
			int cnt = 0;
			
			int max = 0;
			
			for(int i = 0 ; i < n ; i++)
			{
				for(int j = n-1 ; j >= i ; j--)
				{
					if(arr[j] - arr[i] <= d)
					{
						cnt = i + n - j - 1;
						break;
					}
				}
				if(i == 0)
					max = cnt;
				
				if(cnt < max)
					max = cnt;
				cnt = 0;
			}
			
			System.out.println(max);
			
			

		}
	}




