#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = 2e5 + 19;
vector<vector<int>> g;
int d[maxn], c[maxn], p[maxn], val[maxn], ac[maxn];
bool v[maxn];
void dfs(int i) {
  v[i] = true;
  ac[i] = 1;
  for (int it : g[i]) {
    if (!v[it]) {
      p[it] = i;
      d[it] = d[i] + 1;
      dfs(it);
      c[i]++;
      ac[i] += ac[it];
    }
  }
  return;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n, k;
  cin >> n >> k;
  g.resize(n);
  for (int i = 0; i < (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  long long ans = 0;
  for (int i = 0; i < (n); ++i) val[i] = d[i];
  for (int i = 0; i < (n); ++i) v[i] = false;
  priority_queue<pair<long long, long long>> pq;
  for (int i = 0; i < (n); ++i)
    if (c[i] == 0) pq.push(make_pair(val[i], i));
  for (int i = 0; i < (k); ++i) {
    auto it = pq.top();
    pq.pop();
    ans += it.first;
    val[p[it.second]] -= ac[it.second];
    c[p[it.second]]--;
    if (c[p[it.second]] == 0) {
      pq.push(make_pair(val[p[it.second]], p[it.second]));
    }
  }
  cout << ans << endl;
  return 0;
}
