#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long n, k;
vector<long long> e[maxn];
long long vis[maxn], dist[maxn], zhi[maxn], vis1[maxn];
bool cmp(int a, int b) { return a > b; }
void init() {
  cin >> n >> k;
  int x, y;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    int to = e[u][i];
    if (!vis[to]) {
      vis[to] = 1;
      dist[to] = dist[u] + 1;
      dfs(to);
      zhi[u] += zhi[to] + 1;
    }
  }
  dist[u] = dist[u] - zhi[u];
}
int main() {
  init();
  dfs(1);
  sort(dist + 1, dist + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= k; i++) ans += dist[i];
  cout << ans;
  return 0;
}
