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