#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int> > e(n + 1);
  vector<int> sz(n + 1), dep(n + 1);
  for (int i = 0; i <= n - 2; i++) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  vector<int> ans;
  function<void(int, int)> dfs = [&](int u, int p) {
    dep[u] = dep[p] + 1, sz[u] = 1;
    for (int v : e[u]) {
      if (v == p) continue;
      dfs(v, u);
      sz[u] += sz[v];
    }
    ans.push_back(sz[u] - dep[u]);
    return;
  };
  dfs(1, 0);
  sort(ans.rbegin(), ans.rend());
  long long f = 0;
  for (int i = 1; i <= n - k; i++) {
    f += ans[i - 1];
  }
  cout << f << endl;
}
