#Complexity - O(nlogn)
import bisect

n, d = map(int, input().split())
arr = sorted(list(map(int, input().split())))

max_span = 0
for i in range(n):
  pos = bisect.bisect_right(arr, arr[i]+d, i)
  max_span = max(max_span, pos-i)

print(n-max_span)
