N, K = map(int, input().split()) G = [[] for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 G[a].append(b) G[b].append(a) if K >= N + 1: print(-1) else: print(K - 1)