#include <bits/stdc++.h>
using namespace std;
vector<int> v[210010];
priority_queue<int> vi;
int vis[210010];
struct In {
  int dis, pos;
} m[210010];
int cmp(struct In a, struct In b) { return a.dis > b.dis; }
void dfs(int s, int step) {
  m[s].dis = step;
  m[s].pos = 1;
  for (int i = 0; i < v[s].size(); i++) {
    if (vis[v[s][i]]) continue;
    vis[v[s][i]] = 1;
    dfs(v[s][i], step + 1);
    m[s].pos += m[v[s][i]].pos;
    m[s].dis -= m[v[s][i]].pos;
  }
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 2; i <= n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vis[1] = 1;
  dfs(1, 0);
  long long ans = 0;
  sort(m + 1, m + n + 1, cmp);
  for (int i = 1; i <= k; i++) ans += m[i].dis;
  printf("%lld\n", ans);
}
