def main():
    n, d = [int(x) for x in input().split(" ")]
    vals = [int(x) for x in input().split(" ")]
    vals.sort()
    ans = n - 1
    for ind_left in range(n):
        for ind_right in range(ind_left, n, 1):
            v = vals[ind_right] - vals[ind_left]
            if v <= d:
                ans = min(ans, n - ind_right + ind_left - 1)
    print(ans)


if __name__ == "__main__":
    main()

