#include <bits/stdc++.h>
using namespace std;
long long val[200005], sz[200005];
vector<long long> g[200005];
long long power(long long a, long long b, long long m = 1000000007) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long res = power(a, b / 2, m);
  res = (res * res) % m;
  if (b & 1) res = (res * a) % m;
  return res;
}
long long modinv(long long a) { return power(a, 1000000007 - 2); }
bool comp(long long a, long long b) { return a > b; }
long long dfs(long long u, long long par, long long d) {
  sz[u] = 0;
  for (auto v : g[u]) {
    if (v == par) continue;
    sz[u] += dfs(v, u, d + 1);
  }
  val[u] = sz[u] - d;
  return sz[u] + 1;
}
void solve() {
  long long n, k, i, ans = 0, a, b;
  cin >> n >> k;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1, 0);
  sort(val + 1, val + 1 + n, comp);
  for (i = 1; i <= n - k; i++) ans += val[i];
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
