#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
int vis[N];
int par[N];
int level[N];
int subtree[N];
vector<int> adj[N];
void dfs(int curr) {
  vis[curr] = 1;
  subtree[curr] = 1;
  for (auto i : adj[curr]) {
    if (vis[i]) continue;
    par[i] = curr;
    level[i] = level[curr] + 1;
    dfs(i);
    subtree[curr] += subtree[i];
  }
}
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  level[1] = 1;
  par[1] = 0;
  dfs(1);
  int dp[n + 1];
  for (int i = 1; i <= n; i++) {
    dp[i] = subtree[i] - level[i];
  }
  sort(dp + 1, dp + n + 1);
  long long ans = 0;
  for (int i = x + 1; i <= n; i++) {
    ans += dp[i];
  }
  cout << ans << endl;
}
