#include <bits/stdc++.h>
using namespace std;
vector<int> v1[200010];
int depth[200010], size[200010], det[200010];
int dfs(int x, int y) {
  depth[x] = depth[y] + 1;
  size[x] = 1;
  for (int i = 0; i < v1[x].size(); i++) {
    int next = v1[x][i];
    if (next != y) {
      size[x] = size[x] + dfs(next, x);
    }
  }
  det[x] = size[x] - depth[x];
  return size[x];
}
int main() {
  long long n, k, j, ans = 0;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    v1[a].push_back(b);
    v1[b].push_back(a);
  }
  depth[0] = 0;
  dfs(1, 0);
  sort(det + 1, det + n + 1, greater<int>());
  for (int i = 1; i <= n - k; i++) {
    ans += det[i];
  }
  cout << ans << endl;
  return 0;
}
