#include <bits/stdc++.h>
using namespace std;
int N, K, S[(int)(2e5 + 5)], D[(int)(2e5 + 5)], degree[(int)(2e5 + 5)];
bool discovered[(int)(2e5 + 5)], industry[(int)(2e5 + 5)];
vector<int> A, AL[(int)(2e5 + 5)];
long long ans;
void printAL() {
  for (int i = 0; i < N; i++) {
    cout << i << ": ";
    for (int j = 0; j < degree[i]; j++) {
      cout << AL[i][j] << " ";
    }
    cout << "\n";
  }
  cout << "\n";
}
void printS() {
  for (int i = 0; i < N; i++) {
    cout << S[i] << " ";
  }
  cout << "\n";
}
bool mySort(int a, int b) { return (S[a] - D[a] < S[b] - D[b]); }
int dfs(int v) {
  discovered[v] = 1;
  S[v] = 0;
  for (int i = 0; i < degree[v]; i++) {
    int u = AL[v][i];
    if (!discovered[u]) {
      D[u] = D[v] + 1;
      S[v] += dfs(u) + 1;
    }
  }
  return S[v];
}
int dfs2(int v) {
  discovered[v] = 1;
  int mult = industry[v];
  for (int i = 0; i < degree[v]; i++) {
    int u = AL[v][i];
    if (!discovered[u]) {
      mult += dfs2(u);
    }
  }
  if (!industry[v]) {
    ans += mult;
  }
  return mult;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 0; i < N - 1; i++) {
    int v, u;
    cin >> v >> u;
    --v;
    --u;
    AL[v].push_back(u);
    AL[u].push_back(v);
    degree[v]++;
    degree[u]++;
  }
  dfs(0);
  memset(discovered, 0, sizeof(discovered));
  for (int i = 0; i < N; i++) {
    A.push_back(i);
  }
  sort(A.begin(), A.end(), mySort);
  for (int i = 0; i < K; i++) {
    industry[A[i]] = 1;
  }
  dfs2(0);
  cout << ans << "\n";
  return 0;
}
