#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
vector<vi> g;
vector<bool> visited;
void dfs(int node, vector<int>& dist, vector<int>& subtrees) {
  visited[node] = true;
  vector<int> nodes;
  bool leaf = true;
  for (int to : g[node]) {
    if (!visited[to]) {
      dist[to] = dist[node] + 1;
      nodes.push_back(to);
      dfs(to, dist, subtrees);
      leaf = false;
    }
  }
  if (leaf)
    subtrees[node] = 1;
  else {
    subtrees[node] += 1;
    for (int i : nodes) {
      subtrees[node] += subtrees[i];
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  g = vector<vi>(n + 1);
  vi dist(n + 1);
  vi subtrees(n + 1);
  visited = vector<bool>(n + 1);
  for (int i = 0; i < (int)n - 1; i++) {
    int from, to;
    cin >> from >> to;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  dist[1] = 1;
  dfs(1, dist, subtrees);
  vi diff(n + 1);
  for (int i = 1; i < (int)n + 1; i++) {
    diff[i] = subtrees[i] - dist[i];
  }
  sort(diff.begin() + 1, diff.end(), greater<int>());
  ll sum = 0;
  for (int i = 1; i < (int)n - k + 1; i++) {
    sum += diff[i];
  }
  cout << sum << endl;
}
