#include <bits/stdc++.h>
using namespace std;
unordered_map<int, list<int>> m;
void add(int a, int b) {
  m[a].push_back(b);
  m[b].push_back(a);
}
int v[200005] = {0};
int ch[200005] = {0};
vector<int> l;
int dfs1(int node, int c = 1) {
  v[node] = 1;
  int children = 0;
  int ans = 1;
  for (int i : m[node]) {
    if (v[i] == 0) {
      ans = ans + dfs1(i, c + 1);
      children++;
    }
  }
  if (children == 0) ans = 1;
  ch[node] = ans - 1;
  l.push_back(c - 1 - (ch[node]));
  return ans;
}
int main() {
  int n, m1;
  cin >> n >> m1;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
  }
  dfs1(1);
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  long long ans = 0;
  for (int i = 0; i < m1; i++) ans = ans + l[i];
  cout << ans;
}
