#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return x * f;
}
const long long N = 2e5 + 5;
long long val[N], size[N], dep[N];
vector<long long> G[N];
void dfs(long long u, long long fa) {
  size[u] = 1;
  dep[u] = dep[fa] + 1;
  for (long long v : G[u])
    if (v != fa) dfs(v, u), size[u] += size[v];
  val[u] = dep[u] - size[u];
}
signed main() {
  long long n = read(), k = read();
  for (long long i = 1; i < n; ++i) {
    long long u = read(), v = read();
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  sort(val + 1, val + n + 1);
  long long ans = 0;
  for (long long i = 1; i <= n - k; ++i) ans -= val[i];
  printf("%lld\n", ans);
  return 0;
}
