#include <bits/stdc++.h>
using namespace std;
int tot, n, m, k;
int pre[400005], now[400005], v[400005];
struct Node {
  int dep, sum, ans;
  bool friend operator<(Node a, Node b) { return a.ans > b.ans; }
} a[400005];
void ins(int a, int b) {
  ++tot;
  pre[tot] = now[a];
  now[a] = tot;
  v[tot] = b;
}
void dfs(int x, int fa) {
  a[x].sum = 1;
  for (int p = now[x]; p; p = pre[p]) {
    int son = v[p];
    if (son == fa) continue;
    a[son].dep = a[x].dep + 1;
    dfs(son, x);
    a[x].sum += a[son].sum;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ins(x, y);
    ins(y, x);
  }
  dfs(1, -1);
  for (int i = 1; i <= n; i++) a[i].ans = a[i].dep - a[i].sum + 1;
  sort(a + 1, a + n + 1);
  long long ans = 0;
  for (int i = 1; i <= k; i++) ans += (long long)a[i].ans;
  printf("%lld\n", ans);
}
