#include <bits/stdc++.h>
using namespace std;
bool vis[200007];
long long dist[200007], ans = 0;
long long child[200007], ind[200007];
map<long long, long long> m;
vector<pair<long long, long long> > c;
long long dfs2(long long s, vector<long long> adj[]) {
  vis[s] = true;
  long long child = 0;
  for (long long int i = 0; i < adj[s].size(); i++) {
    long long u = adj[s][i];
    if (!vis[u]) child += dfs2(u, adj);
  }
  if (ind[s] == 1)
    child++;
  else
    ans += child;
  return child;
}
long long dfs(long long s, vector<long long> adj[]) {
  vis[s] = true;
  for (long long int i = 0; i < adj[s].size(); i++) {
    if (vis[adj[s][i]] == false) {
      dist[adj[s][i]] = dist[s] + 1;
      child[s] += dfs(adj[s][i], adj);
    }
  }
  return child[s] + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> adj[n + 1];
    for (long long int i = 0; i < n - 1; i++) {
      long long x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dist[1] = 0;
    dfs(1, adj);
    for (long long int i = 1; i < n + 1; i++) {
      c.push_back(make_pair(dist[i] - child[i], i));
    }
    sort(c.begin(), c.end());
    for (long long int i = n - 1; i >= 0; i--) {
      if (k == 0) break;
      ind[c[i].second] = 1;
      k--;
    }
    memset(vis, false, sizeof(vis));
    dfs2(1, adj);
    cout << ans << "\n";
  }
  return 0;
}
