#include <bits/stdc++.h>
using namespace std;
vector<long long> ar[200001];
vector<long long> vec;
int dfs(long long node, long long parent, long long level) {
  long long sum = 0;
  for (long long child : ar[node]) {
    if (child != parent) sum += dfs(child, node, level + 1);
  }
  vec.push_back(level - sum - 1);
  return sum + 1;
}
int main() {
  long long n, k, a, b, ans = 0;
  cin >> n >> k;
  for (int i = 1; i < n; i++)
    cin >> a >> b, ar[a].push_back(b), ar[b].push_back(a);
  dfs(1, -1, 1);
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < k; i++) ans += vec[i];
  cout << ans;
}
