#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
int n, h[MAX], sz[MAX], k, mark[MAX];
long long ans = 0;
vector<int> g[MAX];
void dfs(int v, int p = -1) {
  sz[v] = 0;
  for (int u : g[v])
    if (u != p) h[u] = h[v] + 1, dfs(u, v), sz[v] += sz[u];
  sz[v]++;
}
vector<pair<int, int> > p;
void cal(int v, long long res, int p = -1) {
  if (!mark[v]) res += 1;
  if (mark[v]) ans += res;
  for (int u : g[v])
    if (u != p) cal(u, res, v);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;
  for (int i = 1, v, u; i < n; i++)
    cin >> v >> u, v--, u--, g[v].push_back(u), g[u].push_back(v);
  dfs(0);
  for (int i = 0; i < n; i++) p.push_back({sz[i] - h[i], i});
  sort(p.begin(), p.end());
  for (int i = 0; i < k; i++) mark[p[i].second] = 1;
  cal(0, 0);
  cout << ans << '\n';
  return 0;
}
