#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
vector<int> adj[N];
int dep[N], sz[N];
vector<int> score;
void dfs(int u, int p) {
  sz[u] = 1;
  dep[u] = 1 + dep[p];
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
  score.push_back(dep[u] - sz[u]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  sort(score.rbegin(), score.rend());
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    ans += score[i];
  }
  cout << ans << endl;
}
