#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> md;
unordered_map<int, int> mc;
vector<int> visited;
unordered_set<int> mark;
long long int h = 0ll;
void dfs(int r, int d, vector<vector<int>> &adj) {
  if (!visited[r]) {
    visited[r] = 1;
    md[r] = d;
    for (auto i : adj[r]) {
      dfs(i, d + 1, adj);
    }
  }
}
int dfs2(int r, vector<vector<int>> &adj) {
  if (visited[r]) return 0;
  visited[r] = 1;
  int sum = 1;
  for (auto i : adj[r]) {
    sum += dfs2(i, adj);
  }
  mc[r] = sum;
  return sum;
}
bool compare(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {
  if (a.first.second == b.first.second) return a.first.first < b.first.first;
  return a.first.second > b.first.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; i++) {
    visited.push_back(0);
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  visited.push_back(0);
  dfs(0, 0, adj);
  for (int i = 0; i < n; i++) visited[i] = 0;
  dfs2(0, adj);
  vector<int> node;
  for (int i = 0; i < n; i++) {
    node.push_back(md[i] - mc[i] + 1);
  }
  sort(node.rbegin(), node.rend());
  for (int i = 0; i < k; i++) {
    h += node[i];
  }
  cout << h << endl;
  return 0;
}
