#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 2e5 + 10;
long long sz[maxn], dep[maxn];
vector<long long> g[maxn];
void dfs(long long v, long long p = -1, long long d = 0) {
  dep[v] = d;
  sz[v] = 1;
  for (auto u : g[v]) {
    if (u == p) continue;
    dfs(u, v, d + 1);
    sz[v] += sz[u];
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  vector<long long> a(n);
  long long ans = 0;
  for (long long i = 0; i < n; i++) a[i] = i + 1;
  sort((a).begin(), (a).end(), [&](const long long a, const long long b) {
    return dep[a] - sz[a] > dep[b] - sz[b];
  });
  for (long long i = 0; i < k; i++) {
    ans += dep[a[i]] - sz[a[i]] + 1;
  }
  cout << ans << '\n';
  return 0;
}
