#include <bits/stdc++.h>
using namespace std;
void traverse(vector<vector<int>> &adjlist, int parent, int node,
              vector<pair<long long int, long long int>> &res) {
  res[node - 1].second = 0;
  if (parent == -1) {
    res[node - 1].first = 0;
  } else {
    res[node - 1].first = res[parent - 1].first + 1;
  }
  if (adjlist[node].size() == 0) {
    res[node - 1].second = -1;
    return;
  }
  for (int i = 0; i < adjlist[node].size(); i++) {
    if (adjlist[node][i] == parent) continue;
    traverse(adjlist, node, adjlist[node][i], res);
    res[node - 1].second =
        res[node - 1].second + res[adjlist[node][i] - 1].second;
  }
  res[node - 1].second -= 1;
}
int main() {
  int n, k;
  cin >> n;
  cin >> k;
  vector<int> a;
  vector<vector<int>> adjlist(n + 1, a);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u;
    cin >> v;
    adjlist[u].push_back(v);
    adjlist[v].push_back(u);
  }
  vector<pair<long long int, long long int>> res(n);
  traverse(adjlist, -1, 1, res);
  vector<long long int> x(n);
  for (int i = 0; i < n; i++) {
    x[i] = res[i].first + res[i].second + 1;
  }
  sort(x.begin(), x.end());
  int j = res.size() - 1;
  long long int ans = 0;
  while (k > 0) {
    ans += x[j];
    k--;
    j--;
  }
  cout << ans;
  return 0;
}
