#include <bits/stdc++.h>
using namespace std;
vector<int> graph[500005];
int depth[500005], sub[500005];
multiset<int> ans;
int dfs(int u, int p) {
  depth[u] = depth[p] + 1;
  sub[u] = 1;
  for (int c : graph[u]) {
    if (c != p) {
      sub[u] += dfs(c, u);
    }
  }
  ans.insert(sub[u] - depth[u]);
  return sub[u];
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  long long result = 0;
  dfs(1, 0);
  for (auto u : ans) {
    if (k-- > 0) {
      continue;
    }
    result += u;
  }
  cout << result;
}
