#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200005];
long long sizer[200005] = {0}, depth[200005] = {0}, ans[200005] = {0};
long long comp(long long a, long long b) { return a > b; }
long long dfs(long long u, long long v) {
  depth[u] = depth[v] + 1;
  sizer[u] = 1;
  for (auto x : adj[u]) {
    if (x == v) continue;
    sizer[u] += dfs(x, u);
  }
  ans[u] = sizer[u] - depth[u];
  return sizer[u];
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long u, v, res = 0;
  for (long long i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  std::nth_element(ans + 1, ans + n - k, ans + n + 1, comp);
  for (long long i = 1; i <= n - k; i++) res += ans[i];
  cout << res << endl;
}
