#include <bits/stdc++.h>
using namespace std;
long long ncr(long long n, long long k) {
  if (k > n) return 0;
  if (k * 2 > n) k = n - k;
  if (k == 0) return 1;
  long long result = n;
  for (long long i = 2; i <= k; ++i) {
    result = result * (n - i + 1);
    result /= i;
  }
  return result;
}
long long feelthepower(long long x, long long y) {
  long long res = 1LL;
  while (y) {
    if (y & 1) {
      res = (res * 1LL * x) % 1000000007;
    }
    x = (x * 1LL * x) % 1000000007;
    y /= 2;
  }
  return res;
}
int n, k;
vector<int> adj[200005], hei(200005, 0), sz(200005, 0), res(200005);
int dfs(int s, int parent) {
  hei[s] = hei[parent] + 1;
  sz[s] = 1;
  for (auto x : adj[s]) {
    if (x == parent) continue;
    sz[s] += dfs(x, s);
  }
  res[s] = sz[s] - hei[s];
  return sz[s];
}
int cmp(int a, int b) { return a > b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int tc = 1;
  for (long long ti = 0; ti < tc; ti++) {
    cin >> n >> k;
    for (long long i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(1, 0);
    long long ans = 0LL;
    std::nth_element(res.begin() + 1, res.begin() + n - k, res.begin() + n + 1,
                     cmp);
    for (long long i = 1; i < n - k + 1; i++) {
      ans += res[i];
    }
    cout << ans << endl;
  }
}
