#include using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair P; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template T gcd(T a,T b){return b?gcd(b,a%b):a;} const LL mod=1000000007; const LL LINF=1LL<<62; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; vector G[1<<17]; int main(){ int n,k;cin >> n >> k; if(k > n) puts("-1"); else{ for (int i = 0; i < n-1; i++) { int a,b;cin >> a >> b; a--,b--; G[a].pb(b); G[b].pb(a); } if(k == 1) cout << 0 << endl; else{ priority_queue> q; k -= G[0].size() + 1; int ans = 1; for (int i = 0; i < G[0].size(); i++) { q.push(mp(G[G[0][i]].size(), mp(G[0][i],0))); } while(k > 0){ auto p = q.top();q.pop(); k -= p.fs - 1; ans++; for(auto g:G[p.sc.fs]){ if(g == p.sc.sc) continue; q.push(mp(G[g].size(), mp(g, p.sc.fs))); } } cout << ans << endl; } } return 0; }