#include <bits/stdc++.h>
using namespace std;
int niche_node[200007], parent[200007], depth[200007];
bool vis[200007], tourist[200007];
vector<int> graph[200007];
void dfs(int node) {
  vis[node] = true;
  for (int i = 0; i < graph[node].size(); ++i) {
    if (!vis[graph[node][i]]) {
      parent[graph[node][i]] = node;
      depth[graph[node][i]] = depth[node] + 1;
      dfs(graph[node][i]);
    }
  }
  if (graph[node].size() == 1 && node != 1)
    niche_node[node] = 0;
  else {
    niche_node[node] = 0;
    int child;
    for (int j = 0; j < graph[node].size(); ++j) {
      child = graph[node][j];
      if (child != parent[node]) niche_node[node] += (1 + niche_node[child]);
    }
  }
}
struct data {
  int node;
  long long perform;
  data() {
    node = 0;
    perform = 0;
  }
  bool operator<(const data& p) const { return perform < p.perform; }
} obj;
long long bfs(int root, int k) {
  priority_queue<data> pq;
  obj.node = root;
  obj.perform = niche_node[root];
  pq.push(obj);
  long long sum = 0;
  while (pq.size() && k) {
    obj = pq.top();
    pq.pop();
    tourist[obj.node] = true;
    --k;
    sum += obj.perform;
    for (int i = 0; i < graph[obj.node].size() && k; ++i) {
      if (!tourist[graph[obj.node][i]]) {
        data child_obj;
        child_obj.node = graph[obj.node][i];
        child_obj.perform =
            -(depth[child_obj.node] * (niche_node[child_obj.node] + 1)) +
            ((depth[child_obj.node] + 1) * niche_node[child_obj.node]);
        pq.push(child_obj);
      }
    }
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int test, n, a, b, k;
  cin >> n >> k;
  for (int i = 1; i < n; ++i) {
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i = 0; i <= n; ++i)
    depth[i] = niche_node[i] = vis[i] = parent[i] = tourist[i] = 0;
  dfs(1);
  cout << bfs(1, n - k) << endl;
  return 0;
}
