

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Solution {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] temp = reader.readLine().split("[ ]");
		int n = Integer.parseInt(temp[0]);
		int d = Integer.parseInt(temp[1]);

		temp = reader.readLine().split("[ ]");
		int[] points = new int[n];
		for (int i = 0; i < n; i++) {
			points[i] = Integer.parseInt(temp[i]);
		}

		Solution sol = new Solution();
		System.out.println(sol.solution(points, d));

	}

	public int solution(int[] A, int d) {
		Arrays.sort(A);
		int [][] DP = new int[A.length][A.length];
		for(int i=0;i<DP.length;i++) {
			for(int j=0;j<DP[0].length;j++) {
				DP[i][j]=-1;
			}
		}
		return F(A, d, 0, A.length-1, DP);
	}

	private int F(int[] A, int d, int left, int right,int [][] DP) {
		if (A[right] < A[left]) {
			return 0;
		}

		if (A[right] - A[left] <= d) {
			return 0;
		}
		
		if(DP[left][right]!=-1) {
			return DP[left][right];
		}
		
		DP[left][right]= 1 + Math.min(F(A, d, left + 1, right,DP), F(A, d, left, right -1,DP));
		return DP[left][right];
	}

}
