#include <bits/stdc++.h>
using namespace std;
const char el = '\n';
bool zero[200001];
int numzerobelow[200001];
bool seen[200001];
int subtree[200001];
int disttoroot[200001];
void dfs1(int node, int d, vector<vector<int>>& neighbors) {
  seen[node] = true;
  disttoroot[node] = d;
  for (int neighbor : neighbors[node]) {
    if (seen[neighbor]) continue;
    int child = neighbor;
    dfs1(child, d + 1, neighbors);
  }
}
void dfs2(int node, vector<vector<int>>& neighbors) {
  seen[node] = true;
  for (int neighbor : neighbors[node]) {
    if (seen[neighbor]) continue;
    int child = neighbor;
    dfs2(child, neighbors);
    subtree[node] += subtree[child];
  }
  subtree[node] += 1;
}
void dfs3(int node, vector<vector<int>>& neighbors) {
  seen[node] = true;
  for (int neighbor : neighbors[node]) {
    if (seen[neighbor]) continue;
    int child = neighbor;
    dfs3(child, neighbors);
    numzerobelow[node] += numzerobelow[child];
  }
  if (zero[node] == true) numzerobelow[node] += 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> neighbors(n + 1);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    neighbors[u].push_back(v);
    neighbors[v].push_back(u);
  }
  dfs1(1, 0, neighbors);
  fill(seen, seen + n + 2, 0);
  dfs2(1, neighbors);
  fill(seen, seen + n + 2, 0);
  vector<pair<int, int>> nodebypriority{};
  for (int i = 1; i <= n; ++i) {
    nodebypriority.push_back({disttoroot[i] - subtree[i], i});
  }
  sort(nodebypriority.begin(), nodebypriority.end());
  for (int i = 0; i < k; ++i) {
    int j = nodebypriority[n - 1 - i].second;
    zero[j] = true;
  }
  dfs3(1, neighbors);
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    if (!zero[i]) {
      ret += (long long)numzerobelow[i];
    }
  }
  cout << ret << el;
}
