#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie();
  Main();
  return 0;
}
const int N = 2e5 + 10;
struct edge {
  int v, nxt;
} G[N << 1];
int h[N], tot;
void addedge(int u, int v) {
  G[tot] = {v, h[u]};
  h[u] = tot++;
  G[tot] = {u, h[v]};
  h[v] = tot++;
}
int dep[N], siz[N];
void dfs(int u, int f) {
  siz[u] = 1;
  for (int i = h[u]; ~i; i = G[i].nxt) {
    const int v = G[i].v;
    if (v != f) {
      dep[v] = dep[u] + 1;
      dfs(v, u);
      siz[u] += siz[v];
    }
  }
}
void Main() {
  memset(h, 0xff, sizeof h);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    addedge(u, v);
  }
  dfs(1, -1);
  vector<int> id(n + 1);
  iota(id.begin(), id.end(), 0);
  sort(id.begin() + 1, id.end(), [&](const int& x, const int& y) {
    return dep[x] - siz[x] > dep[y] - siz[y];
  });
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    ans += dep[id[i]] - siz[id[i]] + 1;
  }
  cout << ans << '\n';
}
