#include <bits/stdc++.h>
using namespace std;
void upgrade() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
vector<int> adj[200001];
long long num = 0;
vector<long long> ans;
void dfs(int n, int prev, int d) {
  int cur = num;
  for (int i : adj[n]) {
    if (i != prev) {
      dfs(i, n, d + 1);
    }
  }
  ans.push_back(d - num + cur);
  num++;
}
int main() {
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0, 0);
  sort((ans).begin(), (ans).end(), greater<long long>());
  long long cnt = 0;
  for (int i = 0; i < k; i++) cnt += ans[i];
  cout << cnt << '\n';
}
