#include <bits/stdc++.h>
using namespace std;
long long n, k, happy[200005], zs[200005], sum = 0;
vector<int> G[200005];
void dfs(int x, int fa, long long d) {
  happy[x] = d;
  zs[x] = 1;
  for (int c : G[x]) {
    if (c != fa) {
      dfs(c, x, d + 1);
      zs[x] = zs[x] + zs[c];
      happy[x] = happy[x] - zs[c];
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1, 0);
  sort(happy + 1, happy + 1 + n, greater<long long>());
  for (int i = 1; i <= k; i++) sum += happy[i];
  cout << sum << endl;
  return 0;
}
