#include <bits/stdc++.h>
using namespace std;
bool vis[200001];
list<long long int> adj[200001];
long long int dist[200001], sub[200001];
void dfs(long long int x) {
  vis[x] = true;
  sub[x] = 1;
  for (auto i : adj[x]) {
    if (!vis[i]) {
      dist[i] = dist[x] + 1;
      dfs(i);
      sub[x] += sub[i];
    }
  }
}
int main() {
  long long int i, j, k, m, n, t;
  cin >> n >> m;
  for (i = 0; i < n - 1; i++) {
    cin >> j >> k;
    j--;
    k--;
    adj[j].push_back(k);
    adj[k].push_back(j);
  }
  dist[0] = 1;
  memset(sub, 0, sizeof(vis));
  memset(vis, false, sizeof(vis));
  dfs(0);
  priority_queue<long long int> pq;
  for (i = 0; i < n; i++) pq.push(dist[i] - sub[i]);
  long long int ans = 0;
  while (m > 0) {
    ans += pq.top();
    pq.pop();
    m--;
  }
  cout << ans;
}
