#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 100;
long long cnt[N], d[N], h[N], p[N];
vector<long long> g[N];
void dfs(long long v, long long par) {
  h[v] = (par == -1 ? 0 : h[par] + 1);
  p[v] = par;
  for (auto u : g[v]) {
    if (u == par) continue;
    d[v]++;
    dfs(u, v);
  }
}
int32_t 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 v, u;
    cin >> v >> u;
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0, -1);
  set<pair<long long, long long> > st;
  for (long long i = 0; i < n; i++)
    if (d[i] == 0) st.insert(pair<long long, long long>(h[i], i));
  long long ans = 0;
  while (k) {
    k--;
    pair<long long, long long> V = *st.rbegin();
    st.erase(V);
    long long v = V.second;
    ans += V.first;
    cnt[v]++;
    if (p[v] == -1) continue;
    long long par = p[v];
    d[par]--;
    if (d[par] > 0) continue;
    for (auto u : g[par])
      if (u != p[par]) cnt[par] += cnt[u];
    pair<long long, long long> cur =
        pair<long long, long long>(h[par] - cnt[par], par);
    st.insert(cur);
  }
  cout << ans << "\n";
}
