#include <bits/stdc++.h>
using namespace std;
int n, k;
long long d[200100], s[200100], ans = 0;
vector<int> e[200100];
priority_queue<pair<long long, int> > qu;
void dfs(int u, int parent) {
  s[u] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (v != parent) {
      d[v] = d[u] + 1;
      dfs(v, u);
      s[u] += s[v];
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(1, 1);
  for (int i = 1; i <= n; i++)
    qu.push(pair<long long, int>(d[i] - s[i] + 1, i));
  while (!qu.empty() && k != 0) {
    k--;
    pair<long long, int> top = qu.top();
    qu.pop();
    int u = top.second;
    ans = ans + d[u] - s[u] + 1;
  }
  printf("%lld", ans);
  return 0;
}
