#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
long long o = 0;
int a, k;
vector<vector<int>> l;
vector<int> ds, sz;
void dfs(int v, int p, int d) {
  ds[v] = d;
  sz[v] = 1;
  for (int h : l[v]) {
    if (h != p) {
      dfs(h, v, d + 1);
      sz[v] += sz[h];
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  cin >> a >> k;
  k = a - k;
  l = vector<vector<int>>(a, vector<int>());
  ds = vector<int>(a);
  sz = vector<int>(a);
  for (int q = 0; q < a - 1; q++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    l[x].push_back(y);
    l[y].push_back(x);
  }
  dfs(0, -1, 0);
  vector<long long> kek(a);
  for (int q = 0; q < a; q++) kek[q] = sz[q] - 1 - ds[q];
  sort(kek.begin(), kek.end());
  for (int q = a - 1, i = 0; q >= 0 && i < k; q--, i++) {
    o += kek[q];
  }
  cout << o;
}
