#include <bits/stdc++.h>
using namespace std;
int go(vector<vector<long long>> &graph, long long now,
       vector<pair<long long, long long>> &distances, long long length,
       long long last) {
  int after = 1;
  for (auto next : graph[now]) {
    if (next != last) {
      after += go(graph, next, distances, length + 1, now);
    }
  }
  distances[now].first = length - (after - 1);
  distances[now].second = now;
  return after;
}
long long count_ans(vector<vector<long long>> &graph, long long now,
                    vector<bool> &industrial, long long path, long long last) {
  long long sum = 0;
  if (industrial[now]) {
    sum = path;
  } else {
    ++path;
  }
  for (auto next : graph[now]) {
    if (next != last) {
      sum += count_ans(graph, next, industrial, path, now);
    }
  }
  return sum;
}
int main() {
  long long n, k, u, v;
  cin >> n >> k;
  vector<long long> tmp_v_int;
  vector<vector<long long>> graph(n, tmp_v_int);
  for (long long i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    graph[u - 1].emplace_back(v - 1);
    graph[v - 1].emplace_back(u - 1);
  }
  pair<long long, long long> tmp_pair;
  vector<pair<long long, long long>> distances(n, tmp_pair);
  go(graph, 0, distances, 0, -1);
  sort((distances).begin(), (distances).end());
  vector<bool> industrial(n, false);
  for (long long i = 0; i < k; ++i) {
    industrial[distances[n - i - 1].second] = true;
  }
  cout << fixed << count_ans(graph, 0, industrial, 0, -1) << '\n';
  ;
}
