#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> v(2e5 + 1);
vector<long long> dist(2e5 + 1, INT_MAX), sze(2e5 + 1, 0);
vector<long long> op(2e5 + 1, 0);
long long call_dist(long long node, long long par) {
  dist[node] = dist[par] + 1;
  for (auto i : v[node])
    if (dist[i] == INT_MAX) sze[node] += call_dist(i, node);
  op[node] = dist[node] - sze[node];
  return sze[node] + 1;
}
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dist[0] = -1;
  call_dist(1, 0);
  long long ans = 0, i = n;
  sort(op.begin() + 1, op.begin() + 1 + n);
  while (k--) ans += op[i--];
  cout << ans << endl;
  return 0;
}
