#include <bits/stdc++.h>
using namespace std;
vector<long long> fact((const int)5e5 + 10), invfact((const int)5e5 + 10);
void EE(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  EE(b, a % b, x, y);
  long long temp = x;
  x = y;
  y = temp - (a / b) * y;
}
long long inverse(long long a, long long mod) {
  long long x, y;
  EE(a, mod, x, y);
  return (x + mod) % mod;
}
void build() {
  fact[0] = 1;
  for (long long i = 1; i < (const int)5e5 + 10; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
  invfact[(const int)5e5 + 10 - 1] =
      inverse(fact[(const int)5e5 + 10 - 1], 1000000007);
  for (long long i = (const int)5e5 + 10 - 1 - 1; i >= 0; i--)
    invfact[i] = (invfact[i + 1] * (i + 1)) % 1000000007;
}
long long ncr(long long n, long long r) {
  if (n < 0 || r < 0 || r > n) return 0;
  return (fact[n] * ((invfact[n - r] * invfact[r]) % 1000000007)) % 1000000007;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
long long logy(long long x, long long y) {
  return ceil((long double)(log(x) / log(y)));
}
long long powe(long long a, long long b) {
  long long re = 1;
  while (b) {
    if (b & 1) re = (re * a);
    a = (a * a);
    b = b >> 1;
  }
  return re;
}
long long par[200008], child[200008];
vector<long long> v[200008];
long long n, k;
void dfs(long long node, long long parnode) {
  par[node] = par[parnode] + 1;
  for (long long i = 0; i < v[node].size(); i++) {
    if (v[node][i] != parnode) {
      dfs(v[node][i], node);
      child[node] += child[v[node][i]] + 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  par[0] = -1;
  dfs(1, 0);
  vector<long long> ans;
  for (long long i = 1; i <= n; i++) {
    ans.push_back(par[i] - child[i]);
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  long long anss = 0;
  for (long long i = 0; i < k; i++) {
    anss += ans[i];
  }
  cout << anss;
}
