#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
const long double pi = 3.141592653589793238;
long long MOD = 1000000007;
const long long N = 2e5 + 10;
long long n, k;
vector<long long> graph[N];
long long h[N];
struct cmp {
  bool operator()(pair<long long, pair<long long, long long>> a,
                  pair<long long, pair<long long, long long>> b) {
    return a.first - a.second.second < b.first - b.second.second;
  }
};
priority_queue<pair<long long, pair<long long, long long>>,
               vector<pair<long long, pair<long long, long long>>>, cmp>
    pq;
long long subtree[N] = {0};
bool visited[N];
void preprocess(long long u, long long p, long long level) {
  h[u] = level;
  subtree[u] = 1;
  if (u != 1 && graph[u].size() == 1) pq.push({h[u], {u, 0}});
  for (auto v : graph[u]) {
    if (v == p) continue;
    preprocess(v, u, level + 1);
    subtree[u] += subtree[v];
  }
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  preprocess(1, 1, 0);
  for (long long i = 1; i <= n; i++) subtree[i]--, visited[i] = 0;
  long long sum = 0;
  long long cnt = 0;
  while (1) {
    long long u = pq.top().second.first;
    long long cur = pq.top().first - pq.top().second.second;
    pq.pop();
    if (h[u] - subtree[u] < cur || visited[u]) continue;
    visited[u] = 1;
    sum += h[u] - subtree[u];
    cnt++;
    if (cnt == k) break;
    for (auto v : graph[u]) {
      if (h[v] < h[u]) {
        pq.push({h[v], {v, subtree[v]}});
      }
    }
  }
  cout << sum << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
