#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
vector<int> depth(200005), sz(200005);
vector<long long> cost;
void dfs(int u, int pair) {
  for (int v : g[u]) {
    if (v != pair) {
      depth[v] = depth[u] + 1;
      dfs(v, u);
      sz[u] += sz[v];
    }
  }
  cost.push_back(depth[u] - sz[u]);
  sz[u]++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k, u, v;
  long long ans = 0;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  sort(cost.begin(), cost.end(), greater<long long>());
  for (int i = 0; i < k; i++) ans += cost[i];
  cout << ans << endl;
  return 0;
}
