#include <bits/stdc++.h>
using namespace std;
vector<int> adj[2 * 100002];
vector<int> depth(2 * 100002);
vector<int> subt(2 * 100002, 0);
vector<int> det(2 * 100002);
bool cmp(int a, int b) { return a > b; }
int dfs(int node, int d, int parent) {
  depth[node] = d;
  ;
  for (auto child : adj[node]) {
    if (child != parent) {
      subt[node] += dfs(child, d + 1, node);
    }
  }
  det[node] = depth[node] - subt[node];
  return subt[node] + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, n, l, m;
  cin >> n >> k;
  long long u, v;
  for (i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0, 1);
  sort(det.begin() + 1, det.begin() + n + 1, cmp);
  long long sum = 0;
  for (int j = 1; j <= k; j++) {
    sum += det[j];
  }
  cout << sum << endl;
}
