#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ii = pair<long long, long long>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vec = vector<long long>;
using vecc = vector<vector<long long> >;
namespace royyaha {
template <typename T>
void pr(const T& x) {
  cout << x;
}
template <typename T1, typename T2>
void pr(const pair<T1, T2>& x) {
  cout << x.first << " " << x.second;
}
template <typename T, typename... Args>
void pr(const T& x, const Args&... rest) {
  pr(x);
  pr(rest...);
}
template <typename T>
void ou(const T& x) {
  pr(x);
  cout << endl;
}
template <typename T, typename... Args>
void ou(const T& x, const Args&... rest) {
  pr(x, ' ');
  ou(rest...);
}
template <typename T>
void ou(const vector<T>& v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it + 1 == v.end())
      ou(*it);
    else
      pr(*it, ' ');
  }
}
}  // namespace royyaha
using namespace royyaha;
bool intersection(ii a, ii b) {
  return !(a.first > b.second || a.second < b.first);
}
signed main() {
  long long n, k;
  cin >> n >> k;
  vecc e(n + 1);
  vec ky(n + 1);
  vec mark(n + 1);
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  function<long long(long long, long long, long long)> dfs =
      [&](long long u, long long pre, long long d) {
        long long son = 1;
        for (auto v : e[u])
          if (v != pre) {
            son += dfs(v, u, d + 1);
          };
        ky[u] = d - son;
        return son;
      };
  dfs(1, 1, 0);
  vec idx(n);
  for (long long i = 0; i < n; ++i) idx[i] = i + 1;
  sort(idx.begin(), idx.end(),
       [&](long long a, long long b) { return ky[a] > ky[b]; });
  for (long long i = 0; i < k; ++i) mark[idx[i]] = 1;
  long long ans = 0;
  function<long long(long long, long long, long long)> dfs2 =
      [&](long long u, long long pre, long long d) {
        long long son = mark[u];
        for (auto v : e[u])
          if (v != pre) {
            son += dfs2(v, u, d + 1);
          }
        if (mark[u] == false) ans += son;
        ;
        return son;
      };
  dfs2(1, 1, 0);
  cout << ans << endl;
  ;
}
