#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200005;
int n, k;
vector<int> a[NMAX];
struct DATA {
  int dinh, lv, cons, cnt;
} info[NMAX];
void readData() {
  int x, y;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
    info[i].dinh = i;
  }
  info[n].dinh = n;
}
void DFS(int i) {
  for (int j : a[i]) {
    if (info[j].lv == 0) {
      info[j].lv = info[i].lv + 1;
      DFS(j);
      info[i].cons += info[j].cons;
    }
  }
  info[i].cons++;
  info[i].cnt = info[i].lv - info[i].cons;
}
bool cmp(DATA i1, DATA i2) {
  if (i1.cnt > i2.cnt) return 1;
  return 0;
}
void solve() {
  info[1].lv = 1;
  DFS(1);
  sort(info + 1, info + 1 + n, cmp);
  long long res = 0;
  for (int i = 1; i <= k; i++) res += info[i].cnt;
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  readData();
  solve();
  return 0;
}
