#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  return x;
}
const int N = 200005;
int n, k, a[N], dep[N], sz[N];
long long ans;
vector<int> g[N];
void dfs(int x, int p) {
  dep[x] = dep[p] + 1;
  sz[x] = 1;
  for (int y : g[x])
    if (y != p) {
      dfs(y, x);
      sz[x] += sz[y];
    }
}
int main() {
  n = rd();
  k = rd();
  for (register int i = (1); i <= (n - 1); ++i) {
    int u = rd(), v = rd();
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  for (register int i = (1); i <= (n); ++i) a[i] = dep[i] - sz[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (register int i = (1); i <= (k); ++i) ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
