#include <bits/stdc++.h>
using namespace std;
const long long int maxn = (2 * 1e5) + 2;
long long int d1[maxn], treesize[maxn], f[maxn];
void dfs(long long int node, vector<long long int> adj[],
         long long int visited[]) {
  long long int i;
  visited[node] = 1;
  for (i = 0; i < adj[node].size(); i++) {
    if (!visited[adj[node][i]]) {
      d1[adj[node][i]] = d1[node] + 1;
      dfs(adj[node][i], adj, visited);
      treesize[node] = treesize[node] + treesize[adj[node][i]] + 1;
    }
  }
}
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int i, x, y;
  for (i = 1; i <= n; i++) f[i] = 0;
  for (i = 1; i <= n; i++) treesize[i] = 0;
  vector<long long int> adj[n + 1];
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    f[x]++;
    f[y]++;
  }
  for (i = 0; i <= n; i++) treesize[i] = 0;
  long long int visited[n];
  for (i = 1; i <= n; i++) visited[i] = 0;
  d1[1] = 0;
  dfs(1, adj, visited);
  long long int cost[n + 1];
  cost[0] = INT_MIN;
  for (i = 1; i <= n; i++) {
    cost[i] = d1[i] - treesize[i];
  }
  sort(cost, cost + n + 1, greater<int>());
  long long int tc = 0;
  for (i = 0; i < k; i++) {
    tc = tc + cost[i];
  }
  cout << tc << "\n";
  cerr << "\nTime elapsed:" << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
