#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
#pragma pack(1)
using namespace std;
long long mod = 998244353;
long long inf = 1e9;
long double eps = 1e-6;
double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");
vector<vector<int>> g;
vector<int> subt;
int dfs(int v, int p = -1, int d = 1) {
  int sz = 1;
  for (auto to : g[v]) {
    if (to == p) continue;
    sz += dfs(to, v, d + 1);
  }
  subt[v] = sz - d;
  return sz;
}
int main() {
  int n, k;
  cin >> n >> k;
  g.resize(n);
  subt.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  dfs(0);
  sort(subt.rbegin(), subt.rend());
  long long ans = 0;
  for (int i = 0; i < n - k; i++) {
    ans += subt[i];
  }
  cout << ans;
  return 0;
}
