#include <bits/stdc++.h>
using namespace std;
long long int n, m;
vector<long long int> ar[200001];
long long int vis[200001];
long long int dis[200001];
vector<long long int> val;
long long int dfs(long long int idx, long long int pr, long long int dep) {
  long long int cnt = 0;
  dis[idx] = dep;
  for (auto x : ar[idx]) {
    if (x != pr) {
      cnt += dfs(x, idx, dep + 1);
    }
  }
  val.push_back(dep - cnt);
  return cnt + 1;
}
void solve() {
  long long int test = 1;
  while (test--) {
    cin >> n >> m;
    long long int temp = n - 1;
    while (temp--) {
      long long int a, b;
      cin >> a >> b;
      ar[a].push_back(b);
      ar[b].push_back(a);
    }
    dfs(1, 1, 0);
    sort(val.begin(), val.end(), greater<long long int>());
    long long int sum = 0;
    for (long long int i = 0; i < m; i++) {
      sum += val[i];
    }
    cout << sum << endl;
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
