#include <bits/stdc++.h>
using namespace std;
long long MOD1 = 998244353;
long long MOD2 = 1000000007;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
vector<long long> z_function(string s) {
  long long n = (long long)s.length();
  vector<long long> z(n);
  for (long long i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
vector<long long> prefix_function(string s) {
  long long n = (long long)s.length();
  vector<long long> pi(n);
  for (long long i = 1; i < n; i++) {
    long long j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) j++;
    pi[i] = j;
  }
  return pi;
}
const long long maxn = 200001;
vector<long long> t[maxn];
long long det[maxn], siz[maxn], depth[maxn];
long long dfs(long long u, long long p) {
  siz[u] = 1;
  depth[u] = depth[p] + 1;
  for (long long v : t[u]) {
    if (v == p) continue;
    siz[u] += dfs(v, u);
  }
  det[u] = siz[u] - depth[u];
  return siz[u];
}
void solve() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  dfs(1, 0);
  long long ans = 0;
  nth_element(det + 1, det + n - k, det + n + 1, greater<long long>());
  for (long long i = 1; i <= n - k; ++i) ans += det[i];
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
