#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int maxN = 2e5 + 5;
vector<long long int> adj[maxN];
vector<long long int> sz(maxN, 0);
vector<long long int> vis(maxN, 0);
vector<long long int> dist(maxN, 0);
void dfs(long long int u, long long int p = 0) {
  sz[u] = 1;
  vis[u] = 1;
  dist[u] = 1 + dist[p];
  for (int i = 0; i < adj[u].size(); i++) {
    long long int v = adj[u][i];
    if (vis[v] == 0) {
      dfs(v, u);
      sz[u] += sz[v];
    }
  }
}
int main() {
  long long int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++) sz[i] -= dist[i];
  sort(sz.begin(), sz.begin() + n, greater<int>());
  long long int res = 0;
  for (int i = 0; i < n - k; i++) res += sz[i];
  cout << res << endl;
}
