#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> p;
vector<long long> siz;
vector<int> viz;
vector<int> depth;
vector<int> det;
int dfs(int fr, int bef) {
  depth[fr] = depth[bef] + 1;
  siz[fr] = 1;
  for (int i = 0; i < p[fr].size(); i++) {
    int to = p[fr][i];
    if (to == bef) {
      continue;
    }
    siz[fr] += dfs(to, fr);
  }
  det[fr] = siz[fr] - depth[fr];
  return siz[fr];
}
int main() {
  int n, k;
  cin >> n >> k;
  p.resize(n);
  viz.resize(n);
  siz.resize(n);
  depth.resize(n);
  det.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int fr, to;
    cin >> fr >> to;
    fr--;
    to--;
    p[fr].push_back(to);
    p[to].push_back(fr);
  }
  dfs(0, 0);
  sort(det.begin(), det.end());
  reverse(det.begin(), det.end());
  int c = 0;
  long long s = 0;
  for (int i = 0; i < n - k; i++) {
    s += det[i];
  }
  cout << s;
}
