#include <bits/stdc++.h>
using namespace std;
vector<int> v[200001];
int dis[200001];
int subnd[200001];
void finddis(int s, int p) {
  for (int i = 0; i < v[s].size(); i++) {
    if (v[s][i] == p) {
      continue;
    }
    dis[v[s][i]] = dis[s] + 1;
    finddis(v[s][i], s);
  }
}
void findnod(int s, int p) {
  subnd[s] = 1;
  for (int i = 0; i < v[s].size(); i++) {
    if (v[s][i] == p) {
      continue;
    }
    findnod(v[s][i], s);
    subnd[s] += subnd[v[s][i]];
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  dis[1] = 0;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  finddis(1, 0);
  findnod(1, 0);
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    ans.push_back(dis[i] - subnd[i] + 1);
  }
  sort(ans.begin(), ans.end());
  long long int fans = 0;
  for (int i = n - 1; i >= 0 && k > 0; i-- && k--) {
    fans += ans[i];
  }
  cout << fans << endl;
  return 0;
}
