#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFL = 1e18;
const long long N = 1e5 + 10;
const long long hMod = 239017;
vector<vector<long long> > g;
vector<long long> parent, kol, koll;
vector<pair<long long, long long> > dop;
void dfs(long long v, long long pr, long long kol) {
  parent[v] = pr;
  dop[v].second = v;
  dop[v].first = kol;
  koll[v]++;
  for (auto next : g[v])
    if (next != pr) {
      dfs(next, v, kol + 1);
      koll[v] += koll[next];
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  g.resize(n + 1);
  parent.resize(n + 1);
  kol.resize(n + 1);
  dop.resize(n + 1);
  koll.resize(n + 1);
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0, 0);
  multiset<long long> s;
  for (long long i = 1; i <= n; i++) {
    long long v = dop[i].second;
    long long x = dop[i].first;
    x -= koll[v];
    x++;
    s.insert(x);
  }
  long long ans = 0;
  while (k--) {
    long long x = *s.rbegin();
    ans += x;
    s.erase(s.find(x));
  }
  cout << ans;
  return 0;
}
