#include <bits/stdc++.h>
using namespace std;
long long a, b, c[1234567], d[1234567], c1[1234][1234], e, n, j, i, l, r, x, y,
    k, ans;
bool used[1234567], used1[1234567];
long long T;
multiset<long long> se;
vector<long long> v[1234567], v1;
priority_queue<long long> pq;
void dfs(long long a) {
  used[a] = 1;
  for (auto x : v[a]) {
    if (used[x] == 0) {
      c[x] = c[a] + 1;
      used[x] = 1;
      dfs(x);
      d[a] += d[x] + 1;
    }
  }
  v1.push_back(c[a] - d[a]);
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  c[1] = 0;
  dfs(1);
  sort(v1.begin(), v1.end());
  reverse(v1.begin(), v1.end());
  for (long long i = 0; i <= k - 1; i++) {
    ans += v1[i];
  }
  cout << ans;
}
