#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
int n, k, g, h, u[200001], d[200001];
long long ans;
vector<int> v[200001];
vector<pair<int, int> > tmp;
bool ind[200001];
int dfs(int i, int x, int p) {
  u[i] = x;
  int cnt = 0;
  for (int a : v[i]) {
    if (a == p) continue;
    cnt += dfs(a, x + 1, i);
  }
  d[i] = cnt;
  return 1 + cnt;
}
void dfs1(int i, int x, int p) {
  if (ind[i]) ans += x;
  for (int a : v[i]) {
    if (a == p) continue;
    if (!ind[i])
      dfs1(a, x + 1, i);
    else
      dfs1(a, x, i);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    cin >> g >> h;
    v[g].push_back(h);
    v[h].push_back(g);
  }
  dfs(1, 0, -1);
  for (int i = 1; i < n + 1; i++) {
    tmp.push_back({u[i] - d[i], i});
  }
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());
  for (int i = 0; i < k; i++) {
    ind[tmp[i].second] = true;
  }
  dfs1(1, 0, -1);
  cout << ans;
  return 0;
}
