#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
struct EDGE {
  int to, next;
} edge[MAXN * 2];
int head[MAXN], tot;
void add(int u, int v) {
  tot++;
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot;
}
int deep[MAXN], siz[MAXN], a[MAXN];
void dfs(int s, int fa) {
  siz[s] = 1;
  for (int i = head[s]; i; i = edge[i].next) {
    int po = edge[i].to;
    if (po == fa) continue;
    deep[po] = deep[s] + 1;
    dfs(po, s);
    siz[s] += siz[po];
  }
}
bool cmp(int x, int y) { return y < x; }
int main() {
  int n, k;
  cin >> n >> k;
  tot = 0;
  int u, v;
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  deep[1] = 0;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) deep[i] -= siz[i] - 1;
  sort(deep + 1, deep + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= k; i++) ans += (long long)deep[i];
  cout << ans << endl;
  return 0;
}
