#include <bits/stdc++.h>
using namespace std;
const int mod = pow(10, 9) + 7;
bool compare(pair<int, int> p1, pair<int, int> p2) {
  return p1.second < p2.first;
}
bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {
  long long val1 = p1.first - p1.second;
  long long val2 = p2.first - p2.second;
  return val1 > val2;
}
void open_file() {}
void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
vector<long long> tree[300010];
vector<long long> level(300010, 0);
vector<long long> subtree(300010, 0);
long long n, k;
long long dfs(long long src, long long par, long long lev) {
  level[src] = lev;
  if (tree[src].size() == 1 and src != 0) {
    return 1;
  }
  for (int child : tree[src]) {
    if (child != par) {
      subtree[src] += dfs(child, src, lev + 1);
    }
  }
  return subtree[src] + 1;
}
int main() {
  open_file();
  fast_io();
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  dfs(0, -1, 0);
  vector<long long> A;
  for (long long i = 0; i < n; i++) {
    A.push_back(level[i] - subtree[i]);
  }
  sort(A.begin(), A.end(), greater<long long>());
  long long ans = 0;
  for (int i = 0; i < k; i++) ans += A[i];
  cout << ans << "\n";
  return 0;
}
