#include <bits/stdc++.h>
using namespace std;
int get_greatest_common_div(int x, int y) {
  int result = 1;
  for (int i = 1; i <= min(x, y); i++) {
    if (x % i == 0 && y % i == 0) {
      result = i;
    }
  }
  return result;
}
signed long long dfs(signed long long u, signed long long f,
                     vector<signed long long>& size_arr,
                     vector<vector<signed long long>>& node_arr,
                     vector<signed long long>& depth_arr,
                     vector<signed long long>& gain_arr) {
  signed long long v;
  signed long long x = 1;
  depth_arr[u] = depth_arr[f] + 1;
  for (int i = 0; i < node_arr[u].size(); i++) {
    if ((v = node_arr[u][i]) == f) {
      continue;
    }
    x += dfs(v, u, size_arr, node_arr, depth_arr, gain_arr);
  }
  size_arr[u] = x;
  gain_arr[u] = size_arr[u] - depth_arr[u];
  return x;
}
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<vector<signed long long>> conj(n + 1);
  vector<signed long long> node_size(n + 1, 0);
  vector<signed long long> node_depth(n + 1, 0);
  vector<signed long long> node_gain(n + 1, 0);
  node_gain[0] = INT64_MIN;
  signed long long u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    conj[u].push_back(v);
    conj[v].push_back(u);
  }
  dfs(1, 0, node_size, conj, node_depth, node_gain);
  sort(node_gain.begin(), node_gain.end());
  signed long long ans = 0;
  for (int i = n; i > k; i--) {
    ans += node_gain[i];
  }
  cout << ans << endl;
  return 0;
}
