#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > adj(200005);
long long d[200005];
long long size[200005];
long long parent[200005];
bool vis[200005] = {false};
long long func(long long cur) {
  if (size[cur] != -1) return size[cur];
  long long ans = 0;
  for (long long i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] != parent[cur]) {
      ans += func(adj[cur][i]);
      ans++;
    }
  }
  size[cur] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, k;
    cin >> n >> k;
    for (long long int i = 0; i < n - 1; i++) {
      long long u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    parent[1] = 0;
    d[1] = 0;
    queue<long long> q;
    q.push(1);
    vis[1] = true;
    while (!q.empty()) {
      long long cur = q.front();
      q.pop();
      for (long long i = 0; i < adj[cur].size(); i++) {
        if (!vis[adj[cur][i]]) {
          q.push(adj[cur][i]);
          vis[adj[cur][i]] = true;
          parent[adj[cur][i]] = cur;
          d[adj[cur][i]] = d[cur] + 1;
        }
      }
    }
    for (long long int i = 0; i < n + 1; i++) size[i] = -1;
    func(1);
    long long a[n + 1];
    a[0] = -10000000;
    for (long long int i = 1; i < n + 1; i++) a[i] = size[i] - d[i];
    sort(a + 1, a + n + 1);
    long long ans = 0;
    for (long long i = k + 1; i <= n; i++) ans += a[i];
    cout << ans;
  }
  return 0;
}
