#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, cn[202020];
vector<int> v[202020];
priority_queue<pair<long long, int> > pq;
bool vis[202020];
int dfs(int nw, int bf, int dp) {
  int cnt = 0;
  for (int i = 0; i < v[nw].size(); i++) {
    int yy = v[nw][i];
    if (yy == bf) {
      continue;
    }
    cnt += dfs(yy, nw, dp + 1);
  }
  cn[nw] = dp - cnt;
  return cnt + 1;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0, -1, 0);
  for (int i = 0; i < n; i++) {
    if (v[i].size() == 1) {
      vis[i] = true;
      pq.push(make_pair(cn[i], i));
    }
  }
  while (k) {
    pair<long long, int> p = pq.top();
    pq.pop();
    ans += p.first;
    k--;
    int x = p.second;
    for (int i = 0; i < v[x].size(); i++) {
      if (vis[v[x][i]]) {
        continue;
      }
      vis[v[x][i]] = true;
      pq.push(make_pair(cn[v[x][i]], v[x][i]));
    }
  }
  cout << ans << endl;
  return 0;
}
