def minrem(l, s, e, d):
    if l[e] - l[s] <= d: return 0
    else:
      sdash = s; edash = e
      while l[e] - l[sdash] > d: sdash += 1
      while l[edash] - l[s] > d: edash -= 1
      return min(sdash-s+minrem(l, sdash, e, d), e-edash+minrem(l, s, edash, d))

n, d = raw_input().split()
d = int(d)
l = raw_input().split()
l = [int(i) for i in l]
l = sorted(l)
print minrem(l, 0, int(n)-1, d)