#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N, K = map(int, readline().split()) m = map(int, read().split()) AB = tuple(zip(m, m)) # %% answer = K - 1 if K <= N else - 1 print(answer)