#include <bits/stdc++.h>
using namespace std;
inline void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n, k;
const int mxn = (int)(2e5);
vector<int> adj[mxn + 1];
int dp[mxn + 1];
int sb[mxn + 1];
multiset<int, greater<int>> st;
long long int mx = 0;
void dfs(int u, int p, int h) {
  dp[u] = h;
  sb[u] = 1;
  for (auto it : adj[u]) {
    if (it == p) continue;
    dfs(it, u, h + 1);
    sb[u] += sb[it];
  }
  st.insert(dp[u] - sb[u]);
}
void solve() {
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dp[0] = -1;
  dfs(1, 0, 1);
  while (k > 0) {
    mx += *(st.begin());
    st.erase(st.begin());
    k--;
  }
  cout << mx << endl;
}
int main() {
  fast();
  { solve(); }
}
