#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int n, k, a, b;
vector<int> g[N], children(N);
vector<pair<pair<int, int>, int> > child(N);
vector<bool> mark(N, 0);
int findchild(int root, int par, int level) {
  int add = 1;
  for (int i = 0; i < g[root].size(); i++) {
    if (g[root][i] != par) {
      add += findchild(g[root][i], root, level + 1);
    }
  }
  child[root].first.first = add - level;
  child[root].first.second = add;
  return add;
}
long long calc(int root, int par, long long val) {
  if (mark[root]) {
    return val * children[root];
  }
  long long add = 0;
  for (int i = 0; i < g[root].size(); i++) {
    if (g[root][i] == par) {
      continue;
    } else {
      add += calc(g[root][i], root, val + 1);
    }
  }
  return add;
}
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    child[i + 1].second = i + 1;
  }
  child[n].second = n;
  findchild(1, -1, 1) - 1;
  for (int i = 1; i <= n; i++) {
    children[i] = child[i].first.second;
  }
  sort(child.begin() + 1, child.begin() + n + 1);
  for (int i = 1; i <= k; i++) {
    mark[child[i].second] = 1;
  }
  cout << calc(1, -1, 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
