#include <bits/stdc++.h>
int n, k, x, y;
long long ans = 0;
std::basic_string<int> children[int(2e5)];
std::priority_queue<int> score;
int level[int(2e5)] = {0};
int subtree[int(2e5)] = {0};
void dfs(int node, int father) {
  level[node] = node == 0 ? 0 : level[father] + 1;
  if (children[node].size() == 1 && node != 0) return;
  for (auto i : children[node])
    if (i != father) dfs(i, node);
  subtree[node] = children[node].size() - 1;
  for (auto i : children[node])
    if (i != father) subtree[node] += subtree[i];
  return;
}
int main() {
  std::cin >> n >> k;
  level[0] = -1;
  for (int i = 0; i < n - 1; i++) {
    std::cin >> x >> y;
    children[--x] += --y;
    children[y] += x;
  }
  dfs(0, -1);
  for (int i = 0; i < n; i++) score.push(level[i] - subtree[i]);
  while (k--) ans += score.top(), score.pop();
  std::cout << ans;
}
