#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, k, u, v, a[200010], vis[200010], sum[200010];
vector<int> s[200010];
struct zzz {
  int sum, cnt;
} tt;
struct qqq {
  int id, s;
} fin[200010];
int cmp(qqq x, qqq y) { return x.s > y.s; }
int main() {
  scanf("%d%d", &n, &k);
  memset(a, 0, sizeof(a));
  memset(sum, 0, sizeof(sum));
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    s[u].push_back(v), s[v].push_back(u);
  }
  queue<zzz> q;
  zzz t;
  t.sum = 1, t.cnt = 0;
  q.push(t);
  vis[1] = 1, a[1] = 0;
  while (q.size() > 0) {
    zzz t = q.front();
    q.pop();
    for (int i = 0; i < s[t.sum].size(); i++) {
      if (!vis[s[t.sum][i]]) {
        tt.sum = s[t.sum][i];
        tt.cnt = t.cnt + 1;
        vis[s[t.sum][i]] = 1;
        a[s[t.sum][i]] = tt.cnt;
        q.push(tt);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    fin[i].id = i, fin[i].s = a[i];
  }
  long long ans = 0;
  sort(fin + 1, fin + n + 1, cmp);
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    vis[fin[i].id] = 1;
    for (int j = 0; j < s[fin[i].id].size(); j++) {
      if (!vis[s[fin[i].id][j]]) {
        sum[s[fin[i].id][j]] += sum[fin[i].id] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    fin[i].s -= sum[fin[i].id];
  }
  sort(fin + 1, fin + n + 1, cmp);
  for (int i = 1; i <= k; i++) {
    ans += fin[i].s;
  }
  printf("%lld\n", ans);
  return 0;
}
