#include <bits/stdc++.h>
using namespace std;
long long n, k, passed[200005], ans, q[200005];
vector<long long> dsk[200005];
pair<long long, long long> p[200005];
void input() {
  cin >> n >> k;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    dsk[x].push_back(y);
    dsk[y].push_back(x);
  }
}
void dfs(long long u) {
  passed[u] = 1;
  for (long long i = 0; i < dsk[u].size(); i++) {
    long long v = dsk[u][i];
    if (passed[v]) continue;
    p[v].first = p[u].first - 1;
    dfs(v);
    p[u].second += p[v].second;
  }
}
void solve() {
  for (long long i = 1; i <= n; i++) {
    p[i].second = 1;
  }
  dfs(1);
  for (long long i = 1; i <= n; i++) {
    q[i] = -p[i].first - p[i].second + 1;
  }
  sort(q + 1, q + n + 1);
  for (long long i = n; i >= n - k + 1; i--) {
    ans += q[i];
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  input();
  solve();
}
