#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
vector<vector<int> > g;
vector<int> depth;
vector<int> sel;
int dfs(int par, int curr, int d) {
  int i;
  int cnt = 0;
  for (i = 0; i < (int)g[curr].size(); i++) {
    int next = g[curr][i];
    if (par == next) continue;
    int cnt0 = dfs(curr, next, d + 1);
    cnt += cnt0;
  }
  depth[curr] = d - cnt;
  return cnt + 1;
}
void solve() {
  int n, K;
  scanf("%d%d", &n, &K);
  g.resize(n);
  depth.resize(n);
  int i;
  for (i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(-1, 0, 0);
  sort(depth.rbegin(), depth.rend());
  long long ans = 0;
  for (i = 0; i < K; i++) {
    ans += depth[i];
  }
  printf("%lld\n", ans);
  return;
}
int main(int argc, char* argv[]) {
  solve();
  return 0;
}
