#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long maxn = 1e6 + 5;
const int N = 2e5 + 5;
long long n, k, f[N], s[N];
vector<int> G[N];
void dfs(int x, int fa, long long d) {
  f[x] = d;
  s[x] = 1;
  for (int c : G[x]) {
    if (c == fa) continue;
    dfs(c, x, d + 1);
    s[x] += s[c];
    f[x] -= s[c];
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1, 0);
  sort(f + 1, f + 1 + n, greater<long long>());
  long long res = 0;
  for (int i = 1; i <= k; i++) {
    res += f[i];
  }
  cout << res << '\n';
  return 0;
}
