#include <bits/stdc++.h>
using namespace std;
long long int depth[200005], size[200005], vis[200005];
vector<long long int> g[200005];
bool cmp(long long int a, long long int b) { return a > b; }
int dfs(int u) {
  vis[u] = 1;
  for (long long int i = 0; i < g[u].size(); i++) {
    if (vis[g[u][i]] == 0) {
      depth[g[u][i]] = 1 + depth[u];
      size[u] += 1 + dfs(g[u][i]);
    }
  }
  return size[u];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  while (q--) {
    long long int n, k;
    cin >> n >> k;
    for (long long int i = 0; i < n - 1; i++) {
      long long int x, y;
      cin >> x >> y;
      x--;
      y--;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    dfs(0);
    vector<long long int> a;
    for (long long int i = 0; i < n; i++) a.push_back(depth[i] - size[i]);
    sort(a.begin(), a.end(), cmp);
    int j = 0;
    long long int ans = 0;
    while (k--) {
      ans += a[j];
      j++;
    }
    cout << ans << "\n";
  }
}
