import java.util.Scanner;

public class A940
{
	public static void main(String[] args) 
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int d = in.nextInt();

		int[] x = new int[n];
		int i, j, tmp;
		int[] count = new int[n];
		int[] flag = new int[n];

		for(i=0;i<n;i++)
		{	
			x[i] = in.nextInt();
			flag[i]=-1;
			count[i]=1;
		}
		for(i=0;i<n;i++)
			for(j=0;j<n-i-1;j++)
				if(x[j]>=x[j+1])
				{
					tmp=x[j];
					x[j]=x[j+1];
					x[j+1]=tmp;
				}

		for(i=0;i<n;i++)
		{
			tmp=x[i]+d;
			for(j=i;j<n;j++)
			{	
				if(tmp==x[j])
					flag[i]=j;
			}
		}

		for(i=0;i<n;i++)
		{
			//System.out.println(i + " " + x[i] + " " + flag[i]);
			if(flag[i]!=-1)
				count[i]+=flag[i]-i;
		}

		int max=count[0];
		for(i=1;i<n;i++)
		{	
			if(max<=count[i])
				max=count[i];
		}

		System.out.println(n-max);


	}

}