infinity = float("INF")


def min_diam(dp, ls, i, j, d):
    if dp[i][j] != -1:
        return dp[i][j]
    if i == j:
        return 0
    if i > j:
        return infinity
    if ls[j] - ls[i] <= d:
        return 0
    dp[i][j] = min(min_diam(dp, ls, i + 1, j, d), min_diam(dp, ls, i, j - 1, d)) + 1
    return dp[i][j]


n, d = map(int, raw_input().strip().split())

ls = map(int, raw_input().strip().split())

ls_sorted = sorted(ls)
dp = [[-1 for j in range(n + 1)] for i in range(n + 1)]
print min_diam(dp, ls_sorted, 0, n - 1, d)
