#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200005], aa;
bool visited[200005];
long long dfs(long long s, long long d) {
  long long c = 0, tc = 0, sp, i;
  visited[s] = true;
  for (i = 0; i < adj[s].size(); ++i) {
    if (visited[adj[s][i]] == false) {
      tc += dfs(adj[s][i], d + 1);
    }
  }
  sp = d - tc;
  aa.push_back(sp);
  return tc + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k, i, x, y, ki, ans;
  cin >> n >> k;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (i = 0; i <= n; ++i) visited[i] = false;
  dfs(1, 0);
  sort(aa.begin(), aa.end());
  ki = 0;
  ans = 0;
  for (i = n - 1; i >= 0; i--) {
    ans += aa[i];
    ki++;
    if (ki == k) break;
  }
  cout << ans << '\n';
  return 0;
}
