#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  ios_base::sync_with_stdio(0);
  long long _ = _ = _ = 1;
  for (_; _; --_) {
    solve();
  }
}
const long long N = 4e5 + 13, mod = 998244353;
vector<long long> g[N], kek;
long long dfs(long long v = 1, long long pr = -1, long long cnt = 0) {
  long long st = 0;
  for (long long i : g[v]) {
    if (i != pr) {
      st += dfs(i, v, cnt + 1);
    }
  }
  kek.push_back(cnt - st);
  return st + 1;
}
void solve() {
  long long n, k, ans = 0;
  cin >> n >> k;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs();
  sort(kek.rbegin(), kek.rend());
  for (long long i = 0; k; i++, k--) {
    ans += kek[i];
  }
  cout << ans;
}
