import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] us = new int[n-1]; int[] vs = new int[n-1]; for (int i = 0 , len = n - 1; i < len ; i++){ us[i] = sc.nextInt(); vs[i] = sc.nextInt(); } if(k > n){ System.out.println(-1); }else if(k == 1){ System.out.println(0); }else{ System.out.println(k - 1); } } }