#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
vector<int> G[maxn];
int n, k;
int u, v;
int siz[maxn], dep[maxn];
int val[maxn], fa[maxn];
void dfs(int x, int d) {
  dep[x] = d;
  siz[x] = 1;
  for (int i = 0; i < G[x].size(); ++i) {
    int to = G[x][i];
    if (to == fa[x]) continue;
    fa[to] = x;
    dfs(to, d + 1);
    siz[x] += siz[to];
  }
  val[x] = siz[x] - dep[x];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 1);
  sort(val + 1, val + 1 + n);
  long long ans = 0;
  for (int i = k + 1; i <= n; ++i) ans += (long long)val[i];
  cout << ans;
  return 0;
}
