#include <bits/stdc++.h>
using namespace std;
vector<int> edges[200005];
bool visited[200005];
class node {
 public:
  int cnt, dist;
  bool operator<(const node& a) const { return dist - cnt < a.dist - a.cnt; }
} a[200005];
int dfs(int pos) {
  visited[pos] = true;
  int cnt = 0;
  for (int i = 0; i < edges[pos].size(); i++) {
    if (!visited[edges[pos][i]]) {
      a[edges[pos][i]].dist = a[pos].dist + 1;
      cnt += dfs(edges[pos][i]);
    }
  }
  a[pos].cnt = cnt;
  return cnt + 1;
}
int main() {
  long long ans;
  int n, k, p, q;
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &p, &q);
    edges[p].push_back(q);
    edges[q].push_back(p);
  }
  a[1].dist = 0;
  dfs(1);
  sort(a + 1, a + n + 1);
  ans = 0;
  for (int i = n; i > n - k; i--) {
    ans += a[i].dist - a[i].cnt;
  }
  printf("%lld\n", ans);
  return 0;
}
