#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
inline void print(long long x) {
  if (x < 0) {
    putchar('-');
    print(abs(x));
    return;
  }
  if (x <= 9)
    putchar(x + '0');
  else {
    print(x / 10);
    putchar(x % 10 + '0');
  }
}
inline long long qpow(long long x, long long e, long long _MOD) {
  long long ans = 1;
  while (e) {
    if (e & 1) ans = ans * x % _MOD;
    x = x * x % _MOD;
    e >>= 1;
  }
  return ans;
}
long long n = read(), k = read(), dep[200005], siz[200005], t[200005];
vector<long long> g[200005];
inline void dfs(long long x, long long f) {
  long long cnt = 0;
  siz[x] = 1;
  for (__typeof(g[x].begin()) it = g[x].begin(); it != g[x].end(); it++) {
    long long y = *it;
    if (y != f) {
      cnt++;
      dep[y] = dep[x] + 1;
      dfs(y, x);
      siz[x] += siz[y];
    }
  }
  t[x] = dep[x] - siz[x];
}
signed main() {
  for (long long i = 1; i <= n - 1; i++) {
    long long x = read(), y = read();
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dep[1] = 1;
  dfs(1, 0);
  sort(t + 1, t + n + 1);
  reverse(t + 1, t + n + 1);
  long long ans = 0;
  for (long long i = 1; i <= k; i++) ans += t[i];
  cout << ans << endl;
  return 0;
}
