#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
vector<int> g[N];
long long val[N];
int dfs(int u, int par, int dep) {
  int noc = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int ch = g[u][i];
    if (ch != par) noc += dfs(ch, u, dep + 1);
  }
  val[u] = dep - noc;
  return noc + 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  int u, v;
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0, 0);
  long long ans = 0;
  sort(val + 1, val + n + 1, greater<long long>());
  for (int i = 1; i <= k; ++i) {
    ans += val[i];
  }
  cout << ans << "\n";
  return 0;
}
