#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> g[N], v;
int sz[N];
void dfs(int node, int anc, int h) {
  sz[node] = 1;
  for (int to : g[node]) {
    if (to != anc) {
      dfs(to, node, h + 1);
      sz[node] += sz[to];
    }
  }
  v.push_back(h - sz[node] + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(0, -1, 0);
  sort(v.rbegin(), v.rend());
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    ans += v[i];
  }
  cout << ans;
  return 0;
}
