#include <bits/stdc++.h>
using namespace std;
template <class n, class second>
ostream &operator<<(ostream &p, pair<n, second> x) {
  return p << "<" << x.first << ", " << x.second << ">";
}
template <class n>
auto operator<<(ostream &p, n y) ->
    typename enable_if<!is_same<n, string>::value,
                       decltype(y.begin(), p)>::type {
  int o = 0;
  p << "{";
  for (auto c : y) {
    if (o++) p << ", ";
    p << c;
  }
  return p << "}";
}
void dor() { cerr << '\n'; }
template <class n, class... second>
void dor(n p, second... y) {
  cerr << p << " ";
  dor(y...);
}
template <class n, class second>
void mini(n &p, second y) {
  if (p > y) p = y;
}
template <class n, class second>
void maxi(n &p, second y) {
  if (p < y) p = y;
}
const int MXN = 2e5 + 5;
vector<int> V[MXN];
int odl[MXN];
int podd[MXN];
int dfs(int x, int pp) {
  odl[x] = odl[pp] + 1;
  int pod = 0;
  for (auto i : V[x])
    if (i != pp) pod += dfs(i, x);
  odl[x] = odl[x];
  podd[x] = pod;
  return pod + 1;
}
int type[MXN];
long long sum = 0;
int dfs2(int x, int pp) {
  int pod = 0;
  for (auto i : V[x])
    if (i != pp) pod += dfs2(i, x);
  if (type[x] == 0)
    sum += pod;
  else
    pod++;
  return pod;
}
void solve() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = (1); i <= (int)(n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    V[a].push_back(b);
    V[b].push_back(a);
  }
  dfs(1, 0);
  vector<pair<pair<int, int>, int>> V;
  for (int i = (1); i <= (int)(n); ++i)
    V.push_back(make_pair(make_pair(odl[i] - podd[i], odl[i]), i));
  sort((V).begin(), (V).end());
  reverse((V).begin(), (V).end());
  for (int i = 0; i < (int)(k); ++i) type[V[i].second] = 1;
  dfs2(1, 0);
  cout << sum << '\n';
}
int main() { solve(); }
