#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
vector<vector<int>> adj(2 * 100005);
bool vis[2 * 100005];
int depth[2 * 100005], subtree[2 * 100005];
long long int ans = 0;
int dfs(int u, int d) {
  vis[u] = true;
  int st = 0;
  for (int x : adj[u]) {
    if (!vis[x]) {
      st += dfs(x, d + 1);
    }
  }
  depth[u] = d;
  subtree[u] = st;
  return st + 1;
}
void cp() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  vector<int> v;
  for (int i = 0; i < n; i++) v.push_back(i + 1);
  sort(v.begin(), v.end(), [&](int a, int b) {
    return depth[a] - subtree[a] > depth[b] - subtree[b];
  });
  for (int i = 0; i < k; i++) {
    ans += depth[v[i]] - subtree[v[i]];
  }
  cout << ans;
}
int main() {
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
