#include <bits/stdc++.h>
using namespace std;
const long long MX = 3e5;
long long height[MX];
vector<long long> adj[MX];
long long outdegree[MX];
long long parent[MX];
long long acum[MX];
void dfs(long long u = 0, long long p = -1, long long h = 0) {
  height[u] = h;
  parent[u] = p;
  for (long long v : adj[u]) {
    if (v != p) {
      dfs(v, u, h + 1);
      outdegree[u]++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < (long long)n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs();
  priority_queue<pair<long long, long long>> q;
  long long ans = 0;
  for (long long i = 0; i < (long long)n; i++) {
    if (outdegree[i] == 0) {
      q.push({height[i], i});
      acum[i] = 0;
    }
  }
  for (long long i = 0; i < (long long)k; i++) {
    pair<long long, long long> x = q.top();
    q.pop();
    ans += x.first;
    if (parent[x.second] != -1) {
      long long u = parent[x.second];
      outdegree[u]--;
      acum[u] += acum[x.second] + 1;
      if (outdegree[u] == 0) {
        q.push({height[u] - acum[u], u});
      }
    }
  }
  cout << ans << endl;
  return 0;
}
