#include <bits/stdc++.h>
using namespace std;
const int MSIZE = 2e5 + 5;
const int MOD = 1e9 + 7;
vector<vector<int>> g;
int dp[MSIZE];
int dfs(int x, int par, int lvl) {
  int nodes = 1;
  for (int y : g[x]) {
    if (y != par) nodes += dfs(y, x, lvl + 1);
  }
  dp[x] = nodes - 1 - lvl;
  return nodes;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  g.resize(n + 1);
  for (int i = 0; i <= n - 2; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, -1, 0);
  nth_element(dp + 1, dp + k, dp + n + 1);
  long long sum = 0;
  for (int i = k + 1; i <= n; i++) sum += dp[i];
  cout << sum << endl;
  return 0;
}
