#include <bits/stdc++.h>
using namespace std;
long long int modexp(long long int base, long long int exp) {
  if (exp == 1)
    return base;
  else if (exp == 0)
    return 1;
  else {
    if (exp % 2 == 0) {
      long long int base1 = pow(modexp(base, exp / 2), 2);
      if (base1 >= 1000000007)
        return base1 % 1000000007;
      else
        return base1;
    } else {
      long long int ans = (base * pow(modexp(base, (exp - 1) / 2), 2));
      if (ans >= 1000000007)
        return ans % 1000000007;
      else
        return ans;
    }
  }
}
long long int dep[200005];
long long int siz[200005];
void dfs1(long long int curr, long long int par, vector<long long int>* gr) {
  for (long long int child : gr[curr]) {
    if (child != par) {
      dep[child] = dep[curr] + 1;
      dfs1(child, curr, gr);
    }
  }
}
void dfs2(long long int curr, long long int par, vector<long long int>* gr) {
  if (gr[curr].size() == 1 && gr[curr][0] == par) {
    siz[curr] = 1;
  } else {
    for (long long int child : gr[curr]) {
      if (child != par) {
        dfs2(child, curr, gr);
        siz[curr] += siz[child];
      }
    }
    siz[curr] += 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  vector<long long int> gr[n + 1];
  for (int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  dep[1] = 1;
  dfs1(1, -1, gr);
  dfs2(1, -1, gr);
  long long int diff[n + 1];
  for (long long int i = 1; i <= n; i++) {
    diff[i] = siz[i] - dep[i];
  }
  sort(diff + 1, diff + n + 1);
  long long int ans = 0;
  for (long long int i = 1; i <= n - k; i++) {
    ans += diff[n - i + 1];
  }
  cout << ans << " ";
}
