#include <bits/stdc++.h>
using namespace std;
namespace Qza {
int a[200005], dep[200005], siz[200005];
int en[200005], to[400005], nex[400005];
long long Mod(long long a, long long p) { return a < p ? a : a - p; }
long long max(long long a, long long b) { return a < b ? b : a; }
long long min(long long a, long long b) { return a < b ? a : b; }
void dfs(int x, int f) {
  for (int p = en[x]; p; p = nex[p]) {
    if (to[p] != f) {
      dep[to[p]] = dep[x] + 1;
      dfs(to[p], x);
      siz[x] += siz[to[p]];
    }
  }
  a[x] = dep[x] - siz[x];
  ++siz[x];
}
int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = (x * 10) + (ch ^ 48), ch = getchar();
  return x * f;
}
long long readll() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = (x * 10) + (ch ^ 48), ch = getchar();
  return x * f;
}
void add_edge(int x, int y) {
  static int cnt = 0;
  nex[++cnt] = en[x];
  to[cnt] = y;
  en[x] = cnt;
  nex[++cnt] = en[y];
  to[cnt] = x;
  en[y] = cnt;
}
void main() {
  int n, k;
  long long ans = 0ll;
  n = read();
  k = read();
  for (int i = 1, u, v; i < n; ++i) {
    u = read();
    v = read();
    add_edge(u, v);
  }
  dfs(1, 0);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= n - k + 1; --i) {
    ans += a[i];
  }
  printf("%lld", ans);
}
}  // namespace Qza
int main() {
  Qza::main();
  return 0;
}
