#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 2e5 + 5;
vector<int> E[N];
LL Size[N], Dep[N];
int ord[N];
int tourism[N];
void dfs(int x, int p, int lvl) {
  Size[x] = 1;
  Dep[x] = lvl;
  for (const int &to : E[x]) {
    if (to == p) continue;
    dfs(to, x, lvl + 1);
    Size[x] += Size[to];
  }
}
LL res;
void go(int x, int p, int val) {
  if (tourism[x])
    val++;
  else
    res += val;
  for (const int &to : E[x]) {
    if (to == p) continue;
    go(to, x, val);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  dfs(0, 0, 0);
  iota(ord, ord + n, 0);
  sort(ord, ord + n,
       [](int x, int y) { return Dep[x] - Size[x] < Dep[y] - Size[y]; });
  k = n - k;
  for (int i = 0; i < k; i++) {
    tourism[ord[i]] = 1;
  }
  go(0, 0, 0);
  cout << res << endl;
}
