#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<long long> v1;
vector<long long> deep, niz;
void dfs(int v, int pr) {
  if (v == 0)
    deep[v] = 0;
  else
    deep[v] = deep[pr] + 1;
  long long sum = 0;
  for (int i = 0; i < g[v].size(); i++)
    if (g[v][i] != pr) {
      dfs(g[v][i], v);
      sum += niz[g[v][i]];
    }
  niz[v] = sum + g[v].size() - 1;
  v1.push_back(deep[v] - niz[v]);
}
int main() {
  int n, k;
  cin >> n >> k;
  g.resize(n);
  deep.resize(n);
  niz.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  sort(v1.rbegin(), v1.rend());
  long long ans = 0;
  for (int i = 0; i < k; i++) ans += v1[i];
  cout << ans;
  return 0;
}
