#include <bits/stdc++.h>
using namespace std;
long long quickpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 998244353;
    b >>= 1, a = a * a % 998244353;
  }
  return ans;
}
const long long N = 1e6 + 9;
const long long maxn = 2e5 + 9;
const double esp = 1e-6;
long long head[maxn], tol, dep[maxn];
long long cnt[maxn], vis[maxn];
struct node1 {
  long long s, d;
} b[maxn];
struct node {
  long long v, next;
} g[maxn << 1];
void add(long long u, long long v) {
  g[++tol] = {v, head[u]};
  head[u] = tol;
}
bool cmp(node1 x, node1 y) { return (x.d - x.s) > (y.d - y.s); }
void dfs(long long u, long long pre) {
  b[u].d = b[pre].d + 1;
  b[u].s = 1;
  vis[u] = 1;
  for (long long i = head[u]; i; i = g[i].next) {
    if (!vis[g[i].v]) {
      dfs(g[i].v, u);
      b[u].s += b[g[i].v].s;
    }
  }
}
void solve() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n - 1; i++) {
    long long u, v;
    scanf("%lld%lld", &u, &v);
    add(u, v);
    add(v, u);
  }
  dfs(1, 0);
  sort(b + 1, b + 1 + n, cmp);
  long long ans = 0;
  for (long long i = 1; i <= m; i++) {
    ans += b[i].d - b[i].s;
  }
  cout << ans << "\n";
}
signed main() { solve(); }
