n, k = map(int, input().split()) num = [list(map(int, input().split())) for i in range(n-1)] if k > n : print('-1') else: print(k-1)