import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;



public class Solution {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[] arr = new int[n];
		int elem_cnt = 0;
		for(int i=0;i<n;i++)
			arr[i] = sc.nextInt();
		
		Arrays.sort(arr);
		
		for(int i=0;i<n;i++)
		{
			int cnt = 1;
			for(int j=i+1;j<n;j++)
			{
				if(arr[j]-arr[i] <= d)
					cnt++;
				else
					break;
			}
			elem_cnt = Math.max(elem_cnt, cnt);
		}
		System.out.println(n-elem_cnt);
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}
}
