#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200005;
int tree_size[NMAX] = {0};
vector<int> a[NMAX];
priority_queue<pair<int, int>> q;
int father[NMAX] = {0};
int level[NMAX] = {0};
int c_count[NMAX] = {0};
int subtree[NMAX] = {0};
void dfs(int c, int f) {
  father[c] = f;
  for (int i : a[c]) {
    if (i == f) continue;
    c_count[c]++;
    level[i] = level[c] + 1;
    dfs(i, c);
  }
  if (!c_count[c]) {
    q.push({level[c], c});
  }
}
int main() {
  long long n, k, x, y;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  level[0] = 0;
  dfs(0, -1);
  long long ans = 0;
  while (k--) {
    pair<int, int> m = q.top();
    q.pop();
    int ft = father[m.second];
    ans += m.first;
    subtree[m.second]++;
    if (ft != -1) {
      c_count[ft]--;
      subtree[ft] += subtree[m.second];
      if (c_count[ft] == 0) {
        q.push({level[ft] - subtree[ft], ft});
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
