#include <bits/stdc++.h>
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
using namespace std;
struct edge {
  int t;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y) {
  o->t = y;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n, k;
int dep[MAXN], num[MAXN];
void dfs(int x, int y, int deep) {
  dep[x] = deep;
  num[x] = 1;
  for (edge *j = h[x]; j; j = j->next) {
    if (j->t == y) continue;
    dfs(j->t, x, deep + 1);
    num[x] += num[j->t];
  }
}
bool cmp(int x, int y) { return x > y; }
int main() {
  n = read();
  int x, y, k;
  k = read();
  for (int i = 1; i <= n - 1; i++) x = read(), y = read(), add(x, y), add(y, x);
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) dep[i] -= (num[i] - 1);
  sort(dep + 1, dep + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= k; i++) ans += dep[i];
  printf("%lld\n", ans);
  return 0;
}
