#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k;
vector<int> g[N];
vector<pair<long long, int>> cc;
int v[N];
long long dfs(int u, int d) {
  v[u] = 1;
  long long ans = 0;
  for (auto x : g[u]) {
    if (v[x]) continue;
    ans += dfs(x, d + 1);
    ans++;
  }
  cc.push_back({ans - d, u});
  v[u] = 0;
  return ans;
}
int main() {
  cin >> n >> k;
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  sort(cc.begin(), cc.end(), greater<pair<long long, int>>());
  long long ans = 0;
  for (int i = 0; i < n - k; i++) ans += cc[i].first;
  cout << ans;
}
