import java.io.*;
import java.util.*;

public class A 
{

	static StringBuilder st = new StringBuilder();
	
	public static void main(String[] args) throws Exception 
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt() , d = sc.nextInt();
		
		int []  x = new int [n];
		for(int i = 0 ; i < n ;i++)x[i] =sc.nextInt();
		
		Arrays.sort(x);
		
		
		int max = 0 ; 
		
		for(int i = 0 , j = 0 ; i < n ; i++)
		{
			if(x[i] - x[j] <= d)
			{
				max = Math.max(i - j + 1, max) ; 
				continue ; 
			}
			
			while(j <= i && x[i] - x[j] > d) j ++ ;
			
			max = Math.max(i - j + 1, max) ; 
		}
		
		out.println(n - max);
		
		
		
				
		
		out.flush();
		out.close();
		
	}
	
	
	
	static class Scanner 
	{
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in) 
		{
			 br = new BufferedReader(new InputStreamReader(System.in));
		}
		

		String next() throws Exception 
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
		
			return st.nextToken();
		}

		int nextInt() throws Exception { return Integer.parseInt(next()); }

		long nextLong() throws Exception { return Long.parseLong(next()); }

		double nextDouble() throws Exception { return Double.parseDouble(next()); }
		
	}

	static void shuffle(int[] a) 
	{
		int n = a.length;
		for (int i = 0; i < n; i++) 
		{
			int r = i + (int) (Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}

}