import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from collections import deque



N,K = list(map(int,readline().split()))

m = list(map(int,read().split()))

AB = list(zip(m,m))



graph = [[] for _ in range(N+1)]

for a,b in AB:

    graph[a].append(b)

    graph[b].append(a)



def F(a,b,K):

    INF = 10 ** 9

    if a == b:

        # 中心が1点

        q = deque([a])

        r = K // 2

    else:

        # 中心が辺

        q = deque([a,b])

        r = (K-1)//2

    dist = [INF] * (N+1)

    for x in q:

        dist[x] = 0

    pop = q.popleft; append = q.append

    cnt = len(q)

    while q:

        v = pop()

        dw = dist[v] + 1

        if dw > r:

            break

        for w in graph[v]:

            if dist[w] == INF:

                cnt += 1

                dist[w] = dw

                append(w)

    return N - cnt



if K & 1:

    answer = min(F(a,b,K) for a,b in AB)

else:

    answer = min(F(a,a,K) for a in range(1,N+1))

print(answer)
import sys

import numpy as np



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N, K = list(map(int, readline().split()))

m = list(map(int, read().split()))

G = [[] for _ in range(N + 1)]

for a, b in zip(m, m):

    G[a].append(b)

    G[b].append(a)



def dfs_order(G, root=1):

    parent = [0] * (N + 1)

    order = []

    stack = [root]

    while stack:

        x = stack.pop()

        order.append(x)

        for y in G[x]:

            if y == parent[x]:

                continue

            parent[y] = x

            stack.append(y)

    return parent, order



parent, order = dfs_order(G)



dp1 = np.zeros((N + 1, N + 1), np.int32)

for v in order[::-1]:

    p = parent[v]

    dp1[v, 0] += 1

    dp1[p, 1:] += dp1[v, :-1]



dp2 = np.zeros((N + 1, N + 1), np.int32)

dp2[1] = dp1[1]

for v in order[1:]:

    p = parent[v]

    x = dp2[p].copy()

    x[1:] -= dp1[v, :-1]

    dp2[v, 1:] += x[:-1]

    dp2[v] += dp1[v]



dp3 = np.zeros((N + 1, N + 1), np.int32)

for v in order[1:]:

    p = parent[v]

    dp3[v] = dp1[v]

    x = dp2[p].copy()

    x[1:] -= dp1[v][:-1]

    dp3[v] += x



# 距離 r まで生き残らせるとして、生き残る点の数

dp2.cumsum(axis=1, out=dp2)

dp3.cumsum(axis=1, out=dp3)



if K % 2 == 0:

    x = dp2[:, K // 2].max()

else:

    x = dp3[:, K // 2].max()



print((N - x))
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

N, K = list(map(int, readline().split()))
m = list(map(int, read().split()))
AB = list(zip(m, m))
graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


def F(a, b, K):
    INF = 10**9
    if a == b:
        # 中心が1点
        q = deque([a])
        r = K // 2
    else:
        # 中心が辺
        q = deque([a, b])
        r = (K - 1) // 2
    dist = [INF] * (N + 1)
    for x in q:
        dist[x] = 0
    pop = q.popleft
    append = q.append
    cnt = len(q)
    while q:
        v = pop()
        dw = dist[v] + 1
        if dw > r:
            break
        for w in graph[v]:
            if dist[w] == INF:
                cnt += 1
                dist[w] = dw
                append(w)
    return N - cnt


if K & 1:
    answer = min(F(a, b, K) for a, b in AB)
else:
    answer = min(F(a, a, K) for a in range(1, N + 1))
print(answer)

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
m = list(map(int, read().split()))
G = [[] for _ in range(N + 1)]
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)


def dfs_order(G, root=1):
    parent = [0] * (N + 1)
    order = []
    stack = [root]
    while stack:
        x = stack.pop()
        order.append(x)
        for y in G[x]:
            if y == parent[x]:
                continue
            parent[y] = x
            stack.append(y)
    return parent, order


parent, order = dfs_order(G)
dp1 = np.zeros((N + 1, N + 1), np.int32)
for v in order[::-1]:
    p = parent[v]
    dp1[v, 0] += 1
    dp1[p, 1:] += dp1[v, :-1]
dp2 = np.zeros((N + 1, N + 1), np.int32)
dp2[1] = dp1[1]
for v in order[1:]:
    p = parent[v]
    x = dp2[p].copy()
    x[1:] -= dp1[v, :-1]
    dp2[v, 1:] += x[:-1]
    dp2[v] += dp1[v]
dp3 = np.zeros((N + 1, N + 1), np.int32)
for v in order[1:]:
    p = parent[v]
    dp3[v] = dp1[v]
    x = dp2[p].copy()
    x[1:] -= dp1[v][:-1]
    dp3[v] += x
# 距離 r まで生き残らせるとして、生き残る点の数
dp2.cumsum(axis=1, out=dp2)
dp3.cumsum(axis=1, out=dp3)
if K % 2 == 0:
    x = dp2[:, K // 2].max()
else:
    x = dp3[:, K // 2].max()
print((N - x))

+import numpy as np -from collections import deque - -AB = list(zip(m, m)) -graph = [[] for _ in range(N + 1)] -for a, b in AB: -    graph[a].append(b) -    graph[b].append(a) +G = [[] for _ in range(N + 1)] +for a, b in zip(m, m): +    G[a].append(b) +    G[b].append(a) -def F(a, b, K): -    INF = 10**9 -    if a == b: -        # 中心が1点 -        q = deque([a]) -        r = K // 2 -    else: -        # 中心が辺 -        q = deque([a, b]) -        r = (K - 1) // 2 -    dist = [INF] * (N + 1) -    for x in q: -        dist[x] = 0 -    pop = q.popleft -    append = q.append -    cnt = len(q) -    while q: -        v = pop() -        dw = dist[v] + 1 -        if dw > r: -            break -        for w in graph[v]: -            if dist[w] == INF: -                cnt += 1 -                dist[w] = dw -                append(w) -    return N - cnt +def dfs_order(G, root=1): +    parent = [0] * (N + 1) +    order = [] +    stack = [root] +    while stack: +        x = stack.pop() +        order.append(x) +        for y in G[x]: +            if y == parent[x]: +                continue +            parent[y] = x +            stack.append(y) +    return parent, order -if K & 1: -    answer = min(F(a, b, K) for a, b in AB) +parent, order = dfs_order(G) +dp1 = np.zeros((N + 1, N + 1), np.int32) +for v in order[::-1]: +    p = parent[v] +    dp1[v, 0] += 1 +    dp1[p, 1:] += dp1[v, :-1] +dp2 = np.zeros((N + 1, N + 1), np.int32) +dp2[1] = dp1[1] +for v in order[1:]: +    p = parent[v] +    x = dp2[p].copy() +    x[1:] -= dp1[v, :-1] +    dp2[v, 1:] += x[:-1] +    dp2[v] += dp1[v] +dp3 = np.zeros((N + 1, N + 1), np.int32) +for v in order[1:]: +    p = parent[v] +    dp3[v] = dp1[v] +    x = dp2[p].copy() +    x[1:] -= dp1[v][:-1] +    dp3[v] += x +# 距離 r まで生き残らせるとして、生き残る点の数 +dp2.cumsum(axis=1, out=dp2) +dp3.cumsum(axis=1, out=dp3) +if K % 2 == 0: +    x = dp2[:, K // 2].max() -    answer = min(F(a, a, K) for a in range(1, N + 1)) -print(answer) +    x = dp3[:, K // 2].max() +print((N - x))