#include <bits/stdc++.h>
using namespace std;
struct node {
  long long next, to;
} e[400005];
struct tree {
  long long dep, siz;
} t[200005];
long long head[200005], g;
long long read() {
  long long A;
  bool K;
  char C;
  C = A = K = 0;
  while (C < '0' || C > '9') K |= C == '-', C = getchar();
  while (C > '/' && C < ':') A = (A << 3) + (A << 1) + (C ^ 48), C = getchar();
  return (K ? -A : A);
}
inline bool cmp(tree _, tree __) { return _.dep - _.siz > __.dep - __.siz; }
inline void add(long long u, long long v) {
  e[++g].to = v;
  e[g].next = head[u];
  head[u] = g;
}
void dfs(long long u) {
  long long i, v;
  t[u].siz = 1;
  for (i = head[u]; i; i = e[i].next) {
    v = e[i].to;
    if (!t[v].dep) {
      t[v].dep = t[u].dep + 1;
      dfs(v);
      t[u].siz += t[v].siz;
    }
  }
}
signed main() {
  long long n, k, i, u, v, ans = 0;
  n = read(), k = read();
  for (i = 1; i <= n - 1; i++) {
    u = read(), v = read();
    add(u, v), add(v, u);
  }
  t[1].dep = 1;
  dfs(1);
  sort(t + 1, t + n + 1, cmp);
  for (i = 1; i <= k; i++) ans += t[i].dep - t[i].siz;
  cout << ans;
  return 0;
}
