#include <bits/stdc++.h>
using namespace std;
int const maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }
int head[maxn], cnt;
int dep[maxn], son[maxn];
int pos[maxn];
struct node {
  int v, next;
} e[maxn << 1];
void add(int u, int v) {
  e[cnt].v = v;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
void init() {
  memset(head, -1, sizeof(head));
  cnt = 0;
}
void dfs(int f, int u) {
  dep[u] = dep[f] + 1;
  son[u] = 1;
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v;
    if (v == f) {
      continue;
    }
    dfs(u, v);
    son[u] += son[v];
  }
}
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  init();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    pos[i] = i;
  }
  sort(pos + 1, pos + 1 + n, [](const int &x, const int &y) {
    return dep[x] - son[x] > dep[y] - son[y];
  });
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    ans = ans + (dep[pos[i]] - son[pos[i]]);
  }
  cout << ans << endl;
  return 0;
}
