#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 2e5 + 100;
int n, k, dep[N], flg[N], sz[N];
ll ans;
vi ind, G[N];
void dfs(int x, int fz) {
  sz[x] = 1;
  dep[x] = dep[fz] + 1;
  for (int y : G[x])
    if (y != fz) dfs(y, x), sz[x] += sz[y];
}
void dfs_(int x, int fz, int num) {
  if (flg[x]) ans += num;
  for (int y : G[x])
    if (y != fz) dfs_(y, x, num + !flg[x]);
}
signed main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    G[x].push_back(y), G[y].push_back(x);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) ind.push_back(i);
  sort(ind.begin(), ind.end(), [&](const int a, const int b) {
    return dep[a] - sz[a] > dep[b] - sz[b];
  });
  for (int i = 0; i < k; i++) flg[ind[i]] = 1;
  dfs_(1, 0, 0);
  printf("%lld\n", ans);
  fprintf(stderr, "time=%.4f\n", (db)clock() / CLOCKS_PER_SEC);
  return 0;
}
