#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
int dep[N] = {0}, siz[N] = {0}, f[N], n, k;
vector<int> g[N];
vector<int> ff;
void dfs(int u, int par) {
  siz[u] = 1;
  dep[u] = dep[par] + 1;
  for (auto v : g[u]) {
    if (v != par) {
      dfs(v, u);
      siz[u] += siz[v];
    }
  }
  f[u] = siz[u] - dep[u];
  ff.push_back(f[u]);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  sort(ff.begin(), ff.end());
  reverse(ff.begin(), ff.end());
  long long ans = 0LL;
  for (int i = 0; i < n - k; i++) ans += ff[i];
  cout << ans;
}
