#include <bits/stdc++.h>
using namespace std;
queue<int> q;
vector<int> adjList[200005];
int visit[200005];
int a[200005];
long long depth[200005];
long long siz[200005];
long long ans[200005];
void addEdge(int u, int v) {
  adjList[u].push_back(v);
  adjList[v].push_back(u);
}
long long dfs(long long u) {
  siz[u] = 1;
  for (auto i : adjList[u]) {
    if (!visit[i]) {
      visit[i] = true;
      depth[i] = depth[u] + 1;
      siz[u] += dfs(i);
    }
  }
  return siz[u];
}
void solve(int n, int k) {
  visit[1] = true;
  dfs(1);
  for (int i = 1; i <= n; i++) {
    siz[i]--;
    ans[i] = depth[i] - siz[i];
  }
  sort(ans + 1, ans + n + 1);
  long long val = 0;
  for (int i = n; i > n - k; i--) {
    val += ans[i];
  }
  cout << val;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long vertices, k;
  cin >> vertices >> k;
  for (int i = 1; i < vertices; i++) {
    long long u, v;
    cin >> u >> v;
    addEdge(u, v);
  }
  solve(vertices, k);
  return 0;
}
