#include <bits/stdc++.h>
using namespace std;
vector<int> AdjList[200005];
vector<long long> paths;
long long dfs(int u, int p, int dep) {
  long long tree = 1;
  for (auto v : AdjList[u])
    if (v != p) tree += dfs(v, u, dep + 1);
  paths.push_back(dep - tree + 1);
  return tree;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    AdjList[u].push_back(v);
    AdjList[v].push_back(u);
  }
  dfs(1, 0, 0);
  long long ans = 0;
  sort(paths.rbegin(), paths.rend());
  for (int i = 0; i < min(k, (int)paths.size()); i++) ans += paths[i];
  cout << ans;
  return 0;
}
