#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b, sol;
vector<long long> tree[200010], vis(200010), chld(200010), stat(200010);
vector<pair<long long, long long> > aux;
void dfs1(int src) {
  for (auto u : tree[src])
    if (!vis[u]) vis[u] = vis[src] + 1, dfs1(u);
}
int dfs(int src, int par) {
  long long sum = 0;
  for (auto u : tree[src]) {
    if (u != par) {
      sum += dfs(u, src);
    }
  }
  chld[src] = sum;
  return sum + 1;
}
long long fun(int src, int par) {
  long long sum = 0;
  for (auto u : tree[src]) {
    if (u != par) {
      sum += fun(u, src);
    }
  }
  if (!stat[src]) sol += sum;
  return sum + stat[src];
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++)
    cin >> a >> b, tree[a].push_back(b), tree[b].push_back(a);
  vis[1] = 1;
  dfs1(1);
  dfs(1, -1);
  for (int i = 1; i <= n; i++) {
    vis[i] = vis[i] - 1 - chld[i];
    aux.push_back({vis[i], i});
  }
  sort(aux.begin(), aux.end(), greater<pair<long long, long long> >());
  for (int i = 1; i <= k; i++) stat[aux[i - 1].second] = 1;
  fun(1, -1);
  cout << sol << endl;
  return 0;
}
