You are given an undirected tree with N vertices. The distance between vertices u and v is the number of edges on the simple path from u to v. The diameter of a tree is the maximum distance between any two vertices. A tree is considered "good" if its diameter is at most K. You need to remove zero or more vertices from the tree so that the resulting tree is good. Find the minimum number of vertices that need to be removed to produce a good tree. The constraints are 2≤N≤2000, 1≤K≤N-1, and 1≤A_i, B_i≤N. The input is given in the format N K followed by the edges A_i B_i. Print the minimum number of vertices to remove.

# Buggy version:
import copy

N, K = (int(i) for i in input().split())

G = [[] for i in range(N)]
E = []
for i in range(N-1):
    A, B = (int(i) for i in input().split())
    E.append((A-1, B-1))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

def DFS(u, n, G):
    q = [u]
    v = [0]*N
    d = [0]*N
    while q:
        u1 = q.pop()
        v[u1] += 1
        if d[u1] < n:
            for u2 in G[u1]:
                if not v[u2]:
                    d[u2] = d[u1] + 1
                    q.append(u2)
    return sum(v)

def DFS_E(u, v, n, G):
    return 0

if K % 2 == 0:
    ans = 0
    for v in range(N):
        ans = max(ans, DFS(v, K//2, G))
    print(N-ans)
else:
    ans = 0
    for u, v in E:
        ans = max(ans, DFS_E(u,v,K//2,G))
    print(N-ans)


# Fixed version:
import copy

N, K = (int(i) for i in input().split())

G = [[] for i in range(N)]
E = []
for i in range(N-1):
    A, B = (int(i) for i in input().split())
    E.append((A-1, B-1))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

def DFS(u, n, G):
    q = [u]
    v = [0]*N
    d = [0]*N
    while q:
        u1 = q.pop()
        v[u1] = 1
        if d[u1] < n:
            for u2 in G[u1]:
                if not v[u2]:
                    d[u2] = d[u1] + 1
                    q.append(u2)
    return sum(v)

def DFS_E(u, uu, n, G):
    q = [u, uu]
    v = [0]*N
    d = [0]*N
    while q:
        u1 = q.pop()
        v[u1] = 1
        if d[u1] < n:
            for u2 in G[u1]:
                if not v[u2] and u2 != u:
                    d[u2] = d[u1] + 1
                    q.append(u2)
    return sum(v)


if K % 2 == 0:
    ans = 0
    for v in range(N):
        ans = max(ans, DFS(v, K//2, G))
    print(N-ans)
else:
    ans = 0
    for u, v in E:
        ans = max(ans, DFS_E(u,v,(K-1)//2,G))
    print(N-ans)

# Buggy version:
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len(d for d in dist[i] if d > K / 2))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, sum(adist))

print(ans)


# Fixed version:
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len([d for d in dist[i] if d > K / 2]))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, sum(adist))

print(ans)

# Buggy version:
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len(list(filter(lambda x: K / 2 < x, dist[i]))))
else:
    # 全ての辺について全探索
    for a, b in E:
        dist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, len(list(filter(lambda x: (K-1) / 2 < x, dist))))

print(ans)


# Fixed version:
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len(list(filter(lambda x: K / 2 < x, dist[i]))))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, len(list(filter(lambda x: (K-1) / 2 < x, adist))))

print(ans)