from collections import deque def setPro(t,c,cnt,r,v): v[node_t] = True if r[node_t] == 0: r[node_t] += 1 c -= 1 return (node_t,c,cnt+1,r,v) N,K = map(int,input().split()) g = [[] for _ in range(N)] for _ in range(N-1): a,b = map(int,input().split()) a -= 1 b -= 1 g[a].append(b) g[b].append(a) summary = [0]*N summary[0] = 1 que = deque([(0,K-1,0,summary,[False]*N)]) ans = 10**18 while que: node_f,coin,count,rec,visited = que.popleft() if coin == 0: ans = min(ans,count) elif coin < 0: continue for node_t in g[node_f]: if not visited[node_t]: que.append(setPro(node_t,coin,count,rec,visited)) if ans == 10**18: ans = -1 print(ans)