#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, k;
vector<int> g[N];
int suns[N], dep[N], fas[N];
vector<int> rec;
int cur_dep;
int dfs1(int cur, int fa) {
  cur_dep++;
  fas[cur] = fa;
  for (auto x : g[cur]) {
    if (x == fa) continue;
    dep[x] = cur_dep;
    suns[cur] += dfs1(x, cur);
  }
  cur_dep--;
  rec.push_back(dep[cur] - suns[cur]);
  return suns[cur] + 1;
}
int main() {
  cin >> n >> k;
  while (--n) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(1, -1);
  unsigned long long ans = 0;
  sort(rec.begin(), rec.end());
  reverse(rec.begin(), rec.end());
  for (int i = 0; i < k; i++) ans += rec[i];
  cout << ans;
  return 0;
}
