#include <bits/stdc++.h>
using namespace std;
const int x = 2e5 + 15;
vector<int> adj[x];
long long ans[x];
int dfs(int i, int p, int d) {
  int ch = 0;
  for (int j = 0; j < adj[i].size(); j++) {
    if (adj[i][j] != p) ch += dfs(adj[i][j], i, d + 1);
  }
  ans[i] = d - ch;
  return ch + 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0, 0);
  sort(ans + 1, ans + n + 1, greater<long long>());
  long long res = 0;
  for (int i = 1; i <= k; i++) res += ans[i];
  cout << res << "\n";
  return 0;
}
