#include using namespace std; #define int long long #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)x.size()) template bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template using V = vector; using P = pair; /* * */ int n, k; V es[101010]; int dist[101010]; void dfs(int v, int p, int d){ dist[v] = d; for(int to : es[v]){ if(to == p) continue; dfs(to, v, d+1); } } signed main() { cin >> n >> k; rep(i, 0, n-1){ int a, b; cin >> a >> b; a--; b--; es[a].emplace_back(b); es[b].emplace_back(a); } if(k > n){ cout << -1 << endl; return 0; } dfs(0, -1, 0); sort(dist, dist+n); int ans = 0; rep(i, 0, k) ans += dist[i]; cout << ans << endl; // rep(i, 0, n) cout << dist[i] << " "; // cout << endl; return 0; }