#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long double Pi = 3.141592653;
const long long mod = 1e9 + 7;
long long INF = 1000000000000000000;
bool cmp(pair<int, int> a, pair<int, int> b) {
  return (a.first > b.first) || (a.first == b.first && a.second > b.second);
}
vector<int> adj[200001];
bool visited[200001] = {0};
int level[200001] = {0}, tot[200001] = {0};
vector<int> ans;
int dfs(int n, int p) {
  tot[n] = 1;
  for (int i : adj[n]) {
    if (i == p)
      continue;
    else {
      tot[n] += dfs(i, n);
    }
  }
  return tot[n];
}
void BFS(int v) {
  level[v] = 1;
  visited[v] = true;
  queue<int> q;
  q.push(v);
  while (!q.empty()) {
    v = q.front();
    q.pop();
    for (int i = 0; i < adj[v].size(); i++) {
      if (!visited[adj[v][i]]) {
        visited[adj[v][i]] = true;
        q.push(adj[v][i]);
        level[adj[v][i]] = level[v] + 1;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(1, 0);
    BFS(1);
    long long sum = 0;
    for (int i = 1; i <= n; i++) ans.push_back(tot[i] - level[i]);
    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < n - k; i++) sum += ans[i];
    cout << sum;
  }
}
