#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n, k;
cin >> n >> k;
vector<vector<int>> g(n + 1, vector<int>());
vector<int> dep;
for(int i = 0; i < n - 1; i++){
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
auto dfs = [&](int x, int par, int d, auto && self) -> int {
int cnt = 0;
for(auto y: g[x]){
if(y != par){
cnt += self(y, x, d + 1, self);
}
}
dep.push_back(d - cnt);
return cnt + 1;
};
dfs(1, 0, 0, dfs);
sort(dep.rbegin(), dep.rend());
ll ans = 0;
for(int i = 0; i < k; i++){
ans += dep[i];
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7Cgp2b2lkIHNvbHZlKCl7CglpbnQgbiwgazsKCWNpbiA+PiBuID4+IGs7CgkKCXZlY3Rvcjx2ZWN0b3I8aW50Pj4gZyhuICsgMSwgdmVjdG9yPGludD4oKSk7CgkKCQoJdmVjdG9yPGludD4gZGVwOwoJZm9yKGludCBpID0gMDsgaSA8IG4gLSAxOyBpKyspewoJCWludCB4LCB5OwoJCWNpbiA+PiB4ID4+IHk7CgkJZ1t4XS5wdXNoX2JhY2soeSk7CgkJZ1t5XS5wdXNoX2JhY2soeCk7Cgl9CgkKCWF1dG8gZGZzID0gWyZdKGludCB4LCBpbnQgcGFyLCBpbnQgZCwgYXV0byAmJiBzZWxmKSAtPiBpbnQgewoJCWludCBjbnQgPSAwOwoJCWZvcihhdXRvIHk6IGdbeF0pewoJCQlpZih5ICE9IHBhcil7CgkJCQljbnQgKz0gc2VsZih5LCB4LCBkICsgMSwgc2VsZik7CgkJCX0KCQl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