#!/usr/bin/python3


def func():
    n, d = list(map(int, input().split()))
    a = sorted(list(map(int, input().split())))
#    import pdb
#    pdb.set_trace()
    if n == 1:
        return 0
    m_count = float('inf')
    for i in range(n-1):
        j = i + 1
        count = n-1
        while j < n and a[j] - a[i] <= d:
            count -= 1
            j += 1
        if count < m_count:
            m_count = count
    return m_count


print(func())
