#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int d[200200];
int vis[200200];
vector<int> adj[200200];
int filhos[200200];
int dfs(int x) {
  vis[x] = 1;
  filhos[x] = 0;
  for (auto y : adj[x]) {
    if (!vis[y]) filhos[x] += dfs(y);
  }
  return filhos[x] + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1);
  queue<int> fila;
  fila.push(1);
  for (int i = 1; i <= n; i++) d[i] = INF;
  d[1] = 0;
  while (!fila.empty()) {
    int topo = fila.front();
    fila.pop();
    for (auto y : adj[topo]) {
      if (d[topo] + 1 < d[y]) {
        d[y] = d[topo] + 1;
        fila.push(y);
      }
    }
  }
  priority_queue<pair<int, int>> fila2;
  for (int i = 1; i <= n; i++) {
    fila2.push({d[i] - filhos[i], i});
  }
  long long int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += fila2.top().first;
    fila2.pop();
  }
  cout << ans << endl;
}
