#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &ss, const pair<T1, T2> &a) {
  ss << a.first << ' ' << a.second;
  return ss;
}
template <typename T>
ostream &operator<<(ostream &ss, const vector<T> &v) {
  for (int i = 0; i < v.size(); i++) ss << v[i] << ' ';
  return ss;
}
template <typename T>
ostream &operator<<(ostream &ss, const set<T> &v) {
  for (T i : v) ss << i << ' ';
  return ss;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &ss, const map<T1, T2> &m) {
  for (auto i : m) ss << i << ' ';
  return ss;
}
template <typename T1, typename T2>
istream &operator>>(istream &ss, pair<T1, T2> &a) {
  ss >> a.first >> a.second;
  return ss;
}
template <typename T>
istream &operator>>(istream &ss, vector<T> &v) {
  for (auto &i : v) ss >> i;
  return ss;
}
const long double EPS = 1e-6;
mt19937 gen(221228);
uniform_int_distribution<long long> distr(1, 10);
vector<vector<long long> > v;
vector<long long> ind;
vector<pair<pair<long long, long long>, long long> > sums;
void dfs(long long u, long long p = -1) {
  sums[u].first.first = 1;
  if (p != -1) sums[u].first.second = sums[p].first.second + 1;
  for (long long to : v[u]) {
    if (to == p) continue;
    dfs(to, u);
    sums[u].first.first += sums[to].first.first;
  }
}
long long ans = 0;
void dfa(long long u, long long good = 0, long long p = -1) {
  good += !ind[u];
  if (ind[u]) ans += good;
  for (long long to : v[u]) {
    if (to == p) continue;
    dfa(to, good, u);
  }
  good -= !ind[u];
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long n, k;
  cin >> n >> k;
  v.resize(n);
  sums.resize(n);
  ind.resize(n);
  for (long long i = 0; i < n; i++) sums[i].second = i;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0);
  for (long long i = 0; i < n; i++) {
    sums[i].first.first = sums[i].first.first - sums[i].first.second;
    sums[i].first.second = 0;
  };
  sort(sums.begin(), sums.end());
  for (long long i = 0; i < k; i++) {
    ind[sums[i].second] = 1;
  };
  dfa(0);
  cout << ans;
}
