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