#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> tr;
vector<pair<long long, long long>> de;
set<long long> vis;
queue<pair<long long, long long>> q;
queue<pair<long long, long long>> q2;
vector<long long> dis;
set<long long> done;
void bfs(long long ind, long long val) {
  de[ind].first = val;
  de[ind].second = ind;
  for (long long i = 0; i < tr[ind].size(); i++) {
    if (!vis.count(tr[ind][i])) {
      vis.insert(tr[ind][i]);
      pair<long long, long long> tmpp;
      tmpp.first = tr[ind][i];
      tmpp.second = val + 1;
      q.push(tmpp);
    }
  }
  return;
}
int main() {
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    tr.resize(n);
    pair<long long, long long> tmp;
    tmp.first = 0;
    tmp.second = 0;
    de.resize(n, tmp);
    dis.resize(n, 0);
    for (long long i = 0; i < n - 1; i++) {
      long long tmp1, tmp2;
      cin >> tmp1 >> tmp2;
      tmp1--;
      tmp2--;
      tr[tmp1].push_back(tmp2);
      tr[tmp2].push_back(tmp1);
    }
    pair<long long, long long> start = make_pair(0, 0);
    q.push(start);
    vis.insert(0);
    while (!q.empty()) {
      pair<long long, long long> tmpp = q.front();
      q.pop();
      bfs(tmpp.first, tmpp.second);
    }
    vector<pair<long long, long long>> code = de;
    sort((de).begin(), (de).end());
    reverse((de).begin(), (de).end());
    for (long long i = 0; i < de.size(); i++) {
      done.insert(de[i].second);
      for (long long ii = 0; ii < tr[de[i].second].size(); ii++) {
        if (!done.count(tr[de[i].second][ii])) {
          dis[tr[de[i].second][ii]] += dis[de[i].second] + 1;
        }
      }
    }
    for (long long i = 0; i < code.size(); i++) {
      dis[i] = code[i].first - dis[i];
    }
    sort((dis).begin(), (dis).end());
    reverse((dis).begin(), (dis).end());
    long long ans = 0;
    for (long long i = 0; i < k; i++) {
      ans += dis[i];
    }
    cout << ans << endl;
  }
  return 0;
}
