#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
priority_queue<int> que;
vector<int> mp[200005];
int dep[200005], siz[200005];
void DFS(int last, int now) {
  dep[now] = dep[last] + 1;
  siz[now] = 1;
  for (int i = 0; i < mp[now].size(); i++) {
    if (mp[now][i] != last) {
      DFS(now, mp[now][i]);
      siz[now] += siz[mp[now][i]];
    }
  }
  que.push(dep[now] - siz[now]);
}
int main() {
  int n, k;
  long long sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    mp[u].push_back(v);
    mp[v].push_back(u);
  }
  DFS(0, 1);
  for (int i = 1; i <= k; i++) {
    sum += que.top();
    que.pop();
  }
  cout << sum;
  return 0;
}
