#include <bits/stdc++.h>
using namespace std;
vector<long long> G[200010], sum(200010), l(200010), vis(200010);
void dfs(long long s) {
  vis[s] = 1;
  for (long long i : G[s])
    if (!vis[i]) {
      l[i] = l[s] + 1;
      dfs(i);
      sum[s] += (sum[i] + 1);
    }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k, x, y, i, ans = 0;
  cin >> n >> k;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1);
  vector<long long> nodes;
  for (long long i = 1; i <= n; i++) nodes.push_back(l[i] - sum[i]);
  sort(nodes.begin(), nodes.end());
  reverse(nodes.begin(), nodes.end());
  for (long long i = 0; i < min(k, n); i++) ans += nodes[i];
  cout << ans;
  return 0;
}
