n, k = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n - 1)] if k <= n: ans = k - 1 else: ans = -1 print(ans)