#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589;
const long long int zero = 0;
long long int mod = 1000000007;
char al[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
               'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
vector<int> adj[200000];
int cnt[200000];
int depth[200000];
int visited[200000];
vector<int> v;
int u, siz;
void subtree(int w) {
  cnt[w - 1] = 1;
  vector<int>::iterator it;
  for (it = adj[w - 1].begin(); it != adj[w - 1].end(); it++) {
    if (visited[*it - 1] == 0) {
      visited[*it - 1] = 1;
      subtree(*it);
      cnt[w - 1] += cnt[*it - 1];
    }
  }
}
int main() {
  int t = 1;
  while (t--) {
    int n, k, a, b;
    cin >> n >> k;
    for (long long int i = 0; i < n; i++) {
      cnt[i] = 0;
      depth[i] = 0;
    }
    for (long long int i = 0; i < n - 1; i++) {
      cin >> a >> b;
      adj[a - 1].push_back(b);
      adj[b - 1].push_back(a);
    }
    stack<int> s;
    for (long long int i = 0; i < n; i++) {
      visited[i] = 0;
    }
    visited[0] = 1;
    depth[0] = 1;
    u = 1;
    s.push(1);
    while (!s.empty()) {
      u = s.top();
      s.pop();
      siz = adj[u - 1].size();
      for (long long int j = 0; j < siz; j++) {
        if (visited[adj[u - 1][j] - 1] == 0) {
          depth[adj[u - 1][j] - 1] = depth[u - 1] + 1;
          s.push(adj[u - 1][j]);
          visited[adj[u - 1][j] - 1] = 1;
        }
      }
    }
    for (long long int i = 0; i < n; i++) {
      visited[i] = 0;
    }
    visited[0] = 1;
    subtree(1);
    for (long long int j = 0; j < n; j++) {
      v.push_back(cnt[j] - depth[j]);
    }
    sort(v.rbegin(), v.rend());
    long long int ans = 0;
    for (long long int j = 0; j < n - k; j++) {
      ans += v[j];
    }
    cout << ans;
  }
}
