#include <bits/stdc++.h>
using namespace std;
void setIO(const string &name = "") {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  if (name.length()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
long long n, k;
vector<long long> adj[200010];
vector<long long> numChild, depth, numAtDepth;
long long ans = 0;
void assignChild(long long x, long long prev) {
  for (auto c : adj[x]) {
    if (c != prev) {
      depth[c] = depth[x] + 1;
      assignChild(c, x);
      numChild[x]++;
    }
  }
  for (auto c : adj[x]) {
    if (c != prev) numChild[x] += numChild[c];
  }
}
void solve() {
  vector<long long> sums(n);
  for (auto(i) = 0; i < n; i++) sums[i] = numChild[i] - depth[i];
  sort(sums.rbegin(), sums.rend());
  for (auto(i) = 0; i < k; i++) {
    ans += sums[i];
  }
}
int32_t main() {
  setIO();
  cin >> n >> k;
  k = n - k;
  numChild.assign(n, 0);
  depth.assign(n, 0);
  for (auto(i) = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
  }
  if (k == 0) {
    cout << "0\n";
    return 0;
  }
  assignChild(0, -1);
  solve();
  cout << ans << '\n';
  return 0;
}
