n, d = map(int, raw_input().split())
n = [i for i in map(int, raw_input().split())]

true = True
ans = 0
while true:
    if max(n) - min(n) > d:
        n.remove(max(n))

    else:
        ans = max(n) - min(n)
        break

print ans
