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) visited = [0]*N que = deque([(0,K,0)]) ans = -1 while que: node_f,coin,count = que.pop() if coin == 1: ans = count break for node_t in g[node_f]: if node_t == 0 or visited[node_t] == 0: visited[node_t] += 1 que.append((node_t,coin-1,count+1)) print(ans)