#include <bits/stdc++.h>
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vector<int64_t>>;
using vpii = vector<pair<int64_t, int64_t>>;
using pii = pair<int64_t, int64_t>;
using ll = long long;
using ld = long double;
void R() {}
template <class T, class... U>
inline void R(T &head, U &...tail) {
  cin >> head;
  R(tail...);
}
void W() {}
template <class T, class... U>
inline void W(const T &head, const U &...tail) {
  cout << head << (sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <class T>
void W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); cout << (*i++)) {
    if (i != x.cbegin()) cout << ' ';
  }
  cout << '\n';
}
template <class T>
inline void cmax(T &a, T b) {
  a = max(a, b);
}
template <class T>
inline void cmin(T &a, T b) {
  a = min(a, b);
}
mt19937 rng(time(0));
int64_t n, k;
vi G[200005];
int64_t dep[200005];
int64_t siz[200005];
int64_t id[200005];
int64_t vis[200005];
void dfs(int64_t u, int64_t fa) {
  dep[u] = dep[fa] + 1;
  siz[u] = 1;
  for (int64_t v : G[u]) {
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
}
int64_t pre[200005];
int64_t find(int64_t x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
int64_t solve() {
  cin >> n >> k;
  for (int64_t i = (1); i <= (int64_t)(n - 1); ++i) {
    int64_t u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  auto calc = [&](int64_t x) { return dep[x] - 1 - siz[x] + 1; };
  for (int64_t i = (1); i <= (int64_t)(n); ++i) id[i] = i;
  sort(id + 1, id + 1 + n,
       [&](int64_t a, int64_t b) { return calc(a) > calc(b); });
  int64_t an = 0;
  for (int64_t i = (1); i <= (int64_t)(k); ++i) {
    an += calc(id[i]);
  }
  cout << an << '\n';
  return 0;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  solve();
  return 0;
}
