#include <bits/stdc++.h>
using namespace std;
const int Mn = 2e5 + 17;
struct S {
  int d, sz, id;
} a[Mn];
vector<int> v[Mn];
int dfs1(int x, int d, int fa) {
  int cnt = 0;
  for (int i = 0; i < (int)v[x].size(); ++i) {
    if (v[x][i] != fa) cnt += dfs1(v[x][i], d + 1, x);
  }
  a[x].sz = cnt + 1, a[x].d = d, a[x].id = x;
  return cnt + 1;
}
bool cmp(S x, S y) { return x.d - x.sz > y.d - y.sz; }
bool cmp1(S x, S y) { return x.id < y.id; }
long long ans;
long long dfs2(int x, int fa) {
  long long cnt = 0;
  for (int i = 0; i < (int)v[x].size(); ++i) {
    if (v[x][i] != fa) cnt += dfs2(v[x][i], x);
  }
  if (a[x].sz == -1)
    cnt++;
  else
    ans += cnt;
  return cnt;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int x, y;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y), v[y].push_back(x);
  }
  dfs1(1, 1, -1);
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= k; ++i) a[i].sz = -1;
  sort(a + 1, a + 1 + n, cmp1);
  ans = 0;
  dfs2(1, -1);
  printf("%I64d\n", ans);
}
