#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int modulo = 1e9 + 7;
const int NMAX = 200 * 1000 + 5;
int n, k;
vector<int> g[NMAX];
bool vis[NMAX];
int diff[NMAX];
bool comp(const int &a, const int &b) { return a > b; }
int DFS(int v, int dep) {
  vis[v] = 1;
  int children = 1;
  for (auto &u : (g[v])) {
    if (!vis[u]) children += DFS(u, dep + 1);
  }
  diff[v] = children - dep;
  return children;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  DFS(0, 1);
  sort(diff, diff + n, comp);
  long long res = 0;
  for (int i = 0; i < n - k; ++i) res += diff[i];
  cout << res << "\n";
  return 0;
}
