#include <bits/stdc++.h>
using namespace std;
vector<long long> v[200005], vis(200005, 0), h(200005, -1), sz(200005, 0);
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
void dfs(long long root) {
  vis[root] = 1;
  for (long long i = 0; i < v[root].size(); i++) {
    if (!vis[v[root][i]]) {
      h[v[root][i]] = h[root] + 1;
      dfs(v[root][i]);
      sz[root] += sz[v[root][i]] + 1;
    }
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n - 1; i++) {
    long long x, u;
    cin >> u >> x;
    v[u].push_back(x);
    v[x].push_back(u);
  }
  h[1] = 0;
  dfs(1);
  vector<pair<long long, long long> > vp(n + 1, {INT_MIN, INT_MIN});
  for (long long i = 1; i <= n; i++) {
    vp[i] = {h[i] - sz[i], i};
  }
  sort(vp.begin(), vp.end(), sortinrev);
  long long ans = 0;
  for (long long i = 0; i < k; i++) ans += vp[i].first;
  cout << ans;
}
