#include using namespace std; using lint = long long; using pint = pair; using vi = vector; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() int main() { int n, k; cin >> n >> k; rep(i, n-1) { int a, b; cin >> a >> b; } if (k > n) cout << "-1" << endl; else cout << k-1 << endl; return 0; }