#include <bits/stdc++.h>
using namespace std;
vector<int> gr[200400];
int h[200500];
long long int sz[200500];
int x[200500];
void dfs(int u, int p = 0) {
  h[u] = h[p] + 1;
  sz[u] = 1;
  for (auto v : gr[u]) {
    if (v != p) {
      dfs(v, u);
      sz[u] += sz[v];
    }
  }
}
bool cmp(int a, int b) { return h[a] - sz[a] > h[b] - sz[b]; }
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) x[i - 1] = i;
  for (int i = 2; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  dfs(1);
  sort(x, x + n, cmp);
  long long int ans = 0;
  for (int i = 0; i < k; i++) {
    int t = x[i];
    ans += h[t] - sz[t];
  }
  cout << ans << endl;
  return 0;
}
