#include <bits/stdc++.h>
using namespace std;
vector<int> G[1000000];
int visited[1000000];
int depth[1000000];
int children[1000000];
int dfs(int u, int t, int child) {
  depth[u] = t;
  visited[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int y = G[u][i];
    if (visited[y] == 0) {
      child += dfs(y, t + 1, 0);
    }
  }
  child++;
  children[u] = child;
  return child;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int t = 0;
  dfs(1, 1, 0);
  long long sum = 0;
  vector<long long> happiness;
  for (int i = 1; i <= n; i++) {
    happiness.push_back(depth[i] - children[i]);
  }
  sort(happiness.begin(), happiness.end());
  reverse(happiness.begin(), happiness.end());
  for (int i = 0; i < k; i++) sum += happiness[i];
  cout << sum << endl;
  int count = 0;
}
