#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > g;
vector<bool> vis;
vector<long long> level, cnt;
void bfs(long long p);
void dfs(long long s, long long e);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k, ans = 0;
  cin >> n >> k;
  g.resize(n + 1);
  vis.resize(n + 1, false);
  level.resize(n + 1);
  cnt.resize(n + 1, 0);
  level[0] = -1000000;
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bfs(1);
  dfs(1, 1);
  for (long long i = 1; i < n + 1; ++i) {
    level[i] = level[i] - cnt[i] + 1;
  }
  sort(level.begin(), level.end());
  for (long long i = n; i >= n - k + 1; i--) {
    ans += level[i];
  }
  cout << ans;
  return 0;
}
void bfs(long long p) {
  queue<long long> q;
  q.push(p);
  level[p] = 0;
  vis[p] = 1;
  while (!q.empty()) {
    long long s = q.front();
    q.pop();
    for (long long i = 0; i < g[s].size(); i++) {
      if (!vis[g[s][i]]) {
        level[g[s][i]] = level[s] + 1;
        q.push(g[s][i]);
        vis[g[s][i]] = 1;
      }
    }
  }
}
void dfs(long long s, long long e) {
  cnt[s] = 1;
  for (auto u : g[s]) {
    if (u == e) {
      continue;
    }
    dfs(u, s);
    cnt[s] += cnt[u];
  }
}
