#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> v[N];
bool vis[N];
struct node {
  int cnt, dis;
  bool operator<(const node &a) const { return cnt - dis > a.cnt - a.dis; }
} arr[N];
int dfs(int p, int f) {
  vis[p] = true;
  arr[p].dis = arr[f].dis + 1;
  for (int it : v[p])
    if (!vis[it]) arr[p].cnt += dfs(it, p);
  return arr[p].cnt + 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  arr[0].dis = -1;
  dfs(1, 0);
  sort(arr + 1, arr + 1 + n);
  long long ans = 0;
  for (int i = 1; i <= n - k; i++) ans += arr[i].cnt - arr[i].dis;
  cout << ans << endl;
  return 0;
}
