if __name__ == '__main__':
    n, d = map(int, input().split())
    numbers = list(map(int, input().split()))
    cnt = 0
    # length = len(numbers)
    numbers = sorted(numbers)
    # median = numbers[len(numbers) // 2]
    w = 0
    for i in range(n):
        j = i
        while j < n and numbers[j] - numbers[i] <= d:
            j += 1
        if w < j - i:
            w = j - i
    print(n - w)
 	   	  	  	 	     		 	  						