#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    int N, K;  cin >> N >> K;
    vector<vector<int>> tree(N);
    for(int i=0; i<N-1; i++){
        int a, b;  cin >> a >> b;
        a--;  b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    if(K > N){
        cout << -1 << endl;
        return 0;
    }else{
        cout << K-1 << endl;
    }

}