#include <bits/stdc++.h>
using namespace std;
long long int N = 200005;
vector<long long int> val(N, -1);
void calcval(long long int src, vector<long long int> adj[],
             vector<long long int> &vis, vector<long long int> &dist,
             long long int dis) {
  val[src] = 0;
  vis[src] = 1;
  dist[src] = dis;
  for (long long int i = 0; i < adj[src].size(); i++) {
    if (vis[adj[src][i]] == 0) {
      calcval(adj[src][i], adj, vis, dist, dis + 1);
      val[src] += val[adj[src][i]] + 1;
    }
  }
}
void calcans(long long int src, vector<long long int> adj[],
             vector<long long int> &vis, vector<long long int> &val1,
             vector<long long int> isInd) {
  val1[src] = 0;
  vis[src] = 1;
  for (long long int i = 0; i < adj[src].size(); i++) {
    if (vis[adj[src][i]] == 0) {
      calcans(adj[src][i], adj, vis, val1, isInd);
      if (isInd[adj[src][i]] == 1)
        val1[src] += val1[adj[src][i]] + 1;
      else
        val1[src] += val1[adj[src][i]];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  long long int n, i, j, p, k, m, ans = 0, u, v;
  cin >> n >> k;
  vector<long long int> adj[n];
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v;
    adj[u - 1].push_back(v - 1);
    adj[v - 1].push_back(u - 1);
  }
  vector<long long int> vis(n, 0), isInd(n, 0), vis1, val1(n, -1), dist(n, -1);
  ;
  calcval(0, adj, vis, dist, 0);
  vector<pair<long long int, long long int> > sor;
  long long int pa;
  for (i = 0; i < n; i++) {
    pa = val[i] - dist[i];
    sor.push_back({pa, i});
  }
  sort(sor.begin(), sor.end());
  ans = 0;
  for (i = 0; i < k; i++) {
    isInd[sor[i].second] = 1;
    ans += dist[sor[i].second] - val[sor[i].second];
  }
  cout << ans << endl;
  return 0;
}
