#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long gl[N], s[N];
vector<long long> g[N];
void dfs(long long v, long long p = -1, long long dd = 0) {
  gl[v] = dd;
  s[v] = 1;
  for (long long to : g[v])
    if (to != p) dfs(to, v, dd + 1), s[v] += s[to];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  vector<long long> r;
  cin >> n >> k;
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
  for (long long i = 0; i < n; ++i) r.push_back(gl[i] - s[i] + 1);
  sort(r.begin(), r.end());
  long long ans = 0;
  for (long long i = n - k; i < n; ++i) ans += r[i];
  cout << ans;
}
