N,K = map(int,input().split()) _ = [map(int,input().split()) for _ in range(N-1)] print(K-1 if N >= K else -1)