#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> adj[200005];
int dist[200005], sz[200005];
bool convoy[200005];
vector<pair<int, int> > vec;
long long ans = 0;
void calc(int u, int p, int len) {
  sz[u] = 1;
  dist[u] = len;
  for (auto v : adj[u]) {
    if (v == p) continue;
    calc(v, u, len + 1);
    sz[u] += sz[v];
  }
  vec.push_back(make_pair(dist[u] - sz[u], u));
}
void dfs(int u, int p, long long cnt) {
  if (convoy[u])
    ans += 1LL * cnt;
  else
    cnt += 1;
  for (auto v : adj[u]) {
    if (v == p) continue;
    dfs(v, u, cnt);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  calc(1, -1, 0);
  sort(vec.rbegin(), vec.rend());
  for (int i = 0; i < k; i++) {
    int node = vec[i].second;
    convoy[node] = true;
  }
  dfs(1, -1, 0);
  cout << ans << endl;
}
