import math


def solve(ins, memo, tupl, d):
    if ins[-1] - ins[0] <= d:
        return 0
    if tupl in memo:
        return memo[tupl] 
    memo[(tupl[0] + 1, tupl[1])] = 1 + solve(ins[1:], memo, (tupl[0] + 1, tupl[1]), d)
    memo[(tupl[0], tupl[1]-1)] = 1 + solve(ins[:-1], memo, (tupl[0], tupl[1] - 1), d)
    memo[tupl] = min(memo[(tupl[0] + 1, tupl[1])], memo[(tupl[0], tupl[1] - 1)])
    return memo[tupl]


def main(): 
    n, d = map(int, raw_input().split())
    ins = map(int, raw_input().split())
    ins = sorted(ins)

    if ins[-1] - ins[0] <= d:
        return 0

    out = 0
    return solve(ins, {}, (0, 0), d)

if __name__ == '__main__':
    print main()
