#Kamonasish Roy : Python code
def dfs1(x, p):
for it in edge[x]:
if it != p:
up[it] = up[x] + 1
if x == 1:
low[it] = dp[x][0]
if dp[x][0] == level[it] + 1:
low[it] = dp[x][1]
low[it] -= 1
low[it] = max(low[it], 0)
else:
low[it] = low[x]
cur = dp[x][0]
if dp[x][0] == level[it] + 1:
cur = dp[x][1]
cur -= 1
cur = max(0, cur)
bonus[it] = bonus[x]
bonus[it] += cur
global mx
mx = max(mx, up[it] + min(low[x] + bonus[it], k))
dfs1(it, x)
def dfs(x, p):
for it in edge[x]:
if it != p:
dfs(it, x)
level[p] = max(level[p], level[x] + 1)
if dp[p][0] < level[p]:
dp[p][0], dp[p][1] = level[p], dp[p][0]
elif level[x] + 1 > dp[p][1]:
dp[p][1] = level[x] + 1
if __name__ == "__main__":
import sys
input = sys.stdin.read
data = input().split()
idx = 0
t = 1
results = []
for _ in range(t):
n = int(data[idx])
k = int(data[idx + 1])
idx += 2
global level, dp, low, up, bonus, edge, mx
level = [1] * (n + 1)
dp = [[0, 0] for _ in range(n + 1)]
low = [0] * (n + 1)
up = [0] * (n + 1)
bonus = [0] * (n + 1)
edge = [[] for _ in range(n + 1)]
for i in range(1, n):
x = int(data[idx])
y = int(data[idx + 1])
idx += 2
edge[x].append(y)
edge[y].append(x)
dp[1][0] = 1
dfs(1, 0)
mx = dp[1][0]
up[1] = 1
mx += min(max(0, dp[1][1] - 1), k)
dfs1(1, 0)
results.append(min(mx, n))
print("\n".join(map(str, results)))