from collections import deque 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) for node_t in g[node_f]: if not visited[node_t]: c = coin visited[node_t] = True if rec[node_t] == 0: rec[node_t] += 1 c -= 1 que.append((node_t,c,count+1,rec,visited)) if ans == 10**18: ans = -1 print(ans)