#include <bits/stdc++.h>
using namespace std;
long long a, b = 0, c = 0, e = 0, f = 0, h = 0, hh = 0;
vector<vector<long long>> pp;
vector<long long> v, g, q, vv;
vector<long long> ff, gg, ggg;
void tld(long long aa, long long bb) {
  g[aa] = g[bb] + 1;
  for (auto i : pp[aa]) {
    if (i != bb) {
      v[i] = aa;
      tld(i, aa);
    }
  }
  q[aa] = 1;
  for (auto i : pp[aa]) {
    if (bb != i) {
      q[aa] += q[i];
    }
  }
}
void tls(long long aa, long long bb) {
  gg[aa] = ff[aa];
  for (auto i : pp[aa]) {
    if (i != bb) {
      gg[aa] -= ff[i];
    }
  }
  ggg.push_back(gg[aa]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  a++;
  pp.resize(a);
  g.resize(a);
  v.resize(a);
  q.resize(a);
  gg.resize(a);
  g[0] = 0;
  g[1] = 1;
  for (long long i = 1; i < a - 1; i++) {
    cin >> c >> e;
    pp[c].push_back(e);
    pp[e].push_back(c);
  }
  tld(1, 0);
  ff.resize(a);
  for (long long i = 1; i < a; i++) {
    ff[i] = (g[i] - 1) * q[i];
  }
  for (long long i = 1; i < a; i++) tls(i, v[i]);
  sort(ggg.begin(), ggg.end());
  long long ddd = 0;
  for (long long i = a - 2; i > a - 2 - b; i--) {
    ddd += ggg[i];
  }
  cout << ddd;
}
