#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long powe(long long x, long long y) {
  x = x % mod, y = y % (mod - 1);
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans = (1ll * x * ans) % mod;
    }
    y >>= 1;
    x = (1ll * x * x) % mod;
  }
  return ans;
}
void fun() {}
long long ncr(long long n, long long r) {
  long long res = 1;
  if (r > n) return 0;
  if (r > n - r) r = n - r;
  for (long long i = 0; i < r; i++) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
bool is(char ch) {
  if (ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u')
    return true;
  return false;
}
long long sqvalue(long long a, long long b, long long c) {
  return ((a - b) * (a - b) + (b - c) * (b - c) + (c - a) * (c - a));
}
const long long N = 1e6 + 7;
long long hei[N];
std::vector<long long> v, vv[N];
void dfs(long long node, long long par, long long cur) {
  hei[node] = 1;
  for (auto i : vv[node]) {
    if (i != par) {
      dfs(i, node, cur + 1);
      hei[node] += hei[i];
    }
  }
  v.push_back(cur - hei[node] + 1);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  fun();
  long long ttt = 1;
  while (ttt--) {
    long long n, m;
    cin >> n >> m;
    for (long long i = 0; i < n - 1; i++) {
      long long x, y;
      cin >> x >> y;
      vv[x].push_back(y);
      vv[y].push_back(x);
    }
    dfs(1, 1, 0);
    sort(v.rbegin(), v.rend());
    long long ans = 0;
    for (long long i = 0; i < m; i++) ans += v[i];
    cout << ans;
  }
  return 0;
}
