#include <bits/stdc++.h>
using namespace std;
template <typename T>
T _gcd(T __a, T __b) {
  return !__b ? __a : _gcd(__b, __a % __b);
}
template <typename T>
T _lcm(T __a, T __b) {
  return abs((__a / _gcd(__a, __b)) * __b);
}
template <typename T>
T _pow(T __n, T __p) {
  if (__p <= 1) {
    return (__p == 1) ? __n : 1;
  }
  T R = 1;
  if (__p % 2)
    return __n * _pow(__n, __p - 1);
  else
    R = _pow(__n, __p / 2);
  return R * R;
}
const int N = 2e5 + 500;
vector<vector<int> > Adj;
vector<int> dep, siz, hap;
int n, k;
int DFS(int u, int p) {
  dep[u] = dep[p] + 1;
  siz[u] = 1;
  for (auto v : Adj[u]) {
    if (v == p) continue;
    siz[u] += DFS(v, u);
  }
  return siz[u];
}
int main() {
  cin >> n >> k;
  Adj.assign(n + 1, vector<int>());
  dep.assign(n + 1, 0);
  siz.assign(n + 1, 0);
  hap.assign(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    Adj[u].push_back(v);
    Adj[v].push_back(u);
  }
  DFS(1, 0);
  for (int i = 1; i <= n; i++) hap[i - 1] = dep[i] - siz[i];
  sort(hap.rbegin(), hap.rend());
  long long Ans = 0;
  for (int i = 0; i < k; i++) Ans += (long long)hap[i];
  cout << Ans << endl;
  return 0;
}
