import java.io.*;
import java.util.*;
public class Solution1 {
   
	public static void main(String[]args) throws Exception
	{
	  
	  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	  
	  String[]S=br.readLine().split(" ");
	  
	  int n=Integer.parseInt(S[0]);
	  int x=Integer.parseInt(S[1]);
	  
	  String[]T=br.readLine().split(" ");
	  int[]A=new int[n];
	  
	  for(int i=0;i<n;i++)
	  {
	      A[i]=Integer.parseInt(T[i]);
	  }
	   
	  Arrays.sort(A);
	  
	  int ans=Integer.MAX_VALUE;
	  
	  int i=0;
	  int j=0;
	  
	  while(j<A.length)
	  {
	      if(A[j]-A[i]<=x)
	      {
	          ans=Math.min(ans,n-(j-i+1));
	            j++;
	      }
	      else
	      {
	          i++;
	      }
	      
	  }
	  
	  if(ans!=Integer.MAX_VALUE)
	  System.out.println(ans);
	  else
	  System.out.println("0");
	  
	}
}