#include <bits/stdc++.h>
using ll = long long;
ll n, k;
std::vector<std::vector<int>> tree;
std::vector<int> cnt;
std::vector<int> depth;
void dfs(int u = 0, int pre = -1) {
  for (int i = 0; i < tree[u].size(); i++) {
    int next = tree[u][i];
    if (pre != next) {
      depth[next] = depth[u] + 1;
      dfs(next, u);
    }
  }
  for (int i = 0; i < tree[u].size(); i++) {
    int next = tree[u][i];
    if (pre != next) {
      cnt[u] += cnt[next] + 1;
    }
  }
}
int main() {
  std::cin >> n >> k;
  tree.resize(n);
  cnt.assign(n, 0);
  depth.assign(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    std::cin >> x >> y;
    x--;
    y--;
    tree[x].emplace_back(y);
    tree[y].emplace_back(x);
  }
  dfs();
  std::vector<int> increase(n, 0);
  for (int i = 0; i < n; i++) {
    increase[i] = cnt[i] - depth[i];
  }
  std::sort(increase.begin(), increase.end(), std::greater<int>());
  ll ans = 0;
  for (int i = 0; i < n - k; i++) {
    ans += increase[i];
  }
  std::cout << ans << std::endl;
  return 0;
}
