#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 69;
int n, k;
vector<int> adj[maxn];
int child[maxn], sum[maxn];
int can[maxn];
int h[maxn];
void dfs(int u = 1, int par = -1) {
  child[u] = 1;
  for (auto j : adj[u]) {
    if (j == par) continue;
    h[j] = h[u] + 1;
    dfs(j, u);
    child[u] += child[j];
  }
}
long long ans = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  k = n - k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  h[1] = 1;
  dfs();
  vector<pair<int, int>> f;
  for (int i = 1; i <= n; i++) {
    f.push_back({child[i] - h[i], i});
  }
  long long ans = 0;
  sort(f.rbegin(), f.rend());
  for (int i = 0; i < k; i++) {
    ans += f[i].first;
  }
  cout << ans;
}
