#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ int n, k; cin >> n >> k; vector> g(n); rep(i, n-1) { int a, b; cin >> a >> b; a--; b--; g[a].emplace_back(b); g[b].emplace_back(a); } if (n < k) { cout << -1 << endl; return 0; } vector d(n, 0); queue que; que.push(0); d[0] = 0; int res = 0; while (!que.empty()) { int u = que.front(); que.pop(); for (auto v : g[u]) { if (d[v] != 0) continue; d[v] = d[u] + 1; que.push(v); } } sort(d.begin(), d.end()); for (int i = 0; i < k-1;i++) res += d[i]; cout << res << endl; return 0; }