#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MOD1 = 998244353;
const int MOD3 = 1610612741;
const long long INF = 1e18;
const long long NINF = -1e18;
template <class T>
void _print(T x) {
  cerr << x;
}
template <class T, class V>
void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.first);
  cerr << ",";
  _print(p.second);
  cerr << "}";
}
template <class T>
void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
vector<int> primes;
vector<int> spf;
vector<bool> prime;
long long gcd(long long a, long long b) {
  if (b > a) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long mpow(long long base, long long exp, long long mod) {
  base %= mod;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
long long mAdd(long long a, long long b, long long mod) {
  return (a + b >= mod ? a + b - mod : a + b);
}
void extendgcd(long long a, long long b, long long *v) {
  if (b == 0) {
    v[0] = 1;
    v[1] = 0;
    v[2] = a;
    return;
  }
  extendgcd(b, a % b, v);
  long long x = v[1];
  v[1] = v[0] - v[1] * (a / b);
  v[0] = x;
  return;
}
long long mminv(long long a, long long b) {
  long long arr[3];
  extendgcd(a, b, arr);
  return arr[0];
}
long long mminvprime(long long a, long long b) { return mpow(a, b - 2, b); }
bool revsort(long long a, long long b) { return a > b; }
void swap(int &x, int &y) {
  int temp = x;
  x = y;
  y = temp;
}
long long combination(long long n, long long r, long long m, long long *fact,
                      long long *ifact) {
  long long val1 = fact[n];
  long long val2 = ifact[n - r];
  long long val3 = ifact[r];
  return (((val1 * val2) % m) * val3) % m;
}
void google(int t) { cout << "Case #" << t << ": "; }
long long mod_add(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a + b) % m) + m) % m;
}
long long mod_mul(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a * b) % m) + m) % m;
}
long long mod_sub(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a - b) % m) + m) % m;
}
long long mod_div(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (mod_mul(a, mminvprime(b, m), m) + m) % m;
}
long long phin(long long n) {
  long long number = n;
  if (n % 2 == 0) {
    number /= 2;
    while (n % 2 == 0) n /= 2;
  }
  for (long long i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      number = (number / i * (i - 1));
    }
  }
  if (n > 1) number = (number / n * (n - 1));
  return number;
}
vector<long long> computeHash(string &s) {
  long long str_len = s.length();
  long long p_pow[str_len];
  long long p = 123;
  p_pow[0] = 1;
  for (int i = 1; i < str_len; i++) p_pow[i] = (p_pow[i - 1] * p) % MOD3;
  vector<long long> hash(str_len + 1);
  hash[0] = 0;
  for (int i = 1; i <= str_len; i++)
    hash[i] =
        (hash[i - 1] + ((s[i - 1] - 'a' + 1) * p_pow[i - 1]) % MOD3) % MOD3;
  return hash;
}
vector<int> makeZarray(string s) {
  int n = s.length();
  vector<int> z(n);
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
void sieve(int n) {
  prime.assign(n + 1, true);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i <= n; i++)
    if (prime[i] == 1) {
      primes.emplace_back(i);
      for (long long j = (long long)i * i; j <= n; j += i) {
        if (prime[j]) prime[j] = 0;
      }
    }
}
void find_spf(int n) {
  n = max(n, 1);
  spf.assign(n + 1, 0);
  prime.assign(n + 1, true);
  prime[0] = prime[1] = false;
  int i;
  for (i = 2; i <= n; i++) {
    if (prime[i]) {
      primes.emplace_back(i);
      spf[i] = i;
      for (long long j = (long long)i * i; j <= n; j += i) {
        if (prime[j]) {
          prime[j] = false;
          spf[j] = i;
        }
      }
    }
  }
}
vector<pair<long long, long long> > prime_factorize(long long n) {
  vector<pair<long long, long long> > result;
  if (n < spf.size()) {
    while (n != 1) {
      long long fact = spf[n];
      long long exp = 0;
      do {
        n /= fact;
        exp++;
      } while (n % fact == 0);
      result.emplace_back(fact, exp);
    }
    return result;
  } else {
    for (auto p : primes) {
      if (p * p > n) break;
      if (n % p == 0) {
        result.emplace_back(p, 0);
        do {
          n /= p;
          result.back().second++;
        } while (n % p == 0);
      }
    }
    if (n > 1) result.emplace_back(n, 1);
    return result;
  }
}
long long sumprimeExp(long long n) {
  vector<pair<long long, long long> > prime_factors = prime_factorize(n);
  long long ans = 0;
  for (auto p : prime_factors) {
    ans += p.second;
  }
  return ans;
}
vector<int> descendants;
vector<int> depth;
void dfs(vector<vector<int> > &adj, int u, int par, int distFromRoot) {
  depth[u] = distFromRoot;
  descendants[u] = 0;
  for (auto v : adj[u]) {
    if (v != par) {
      dfs(adj, v, u, distFromRoot + 1);
      descendants[u] += (1 + descendants[v]);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<vector<int> > adj(n + 1);
    depth.resize(n + 1, 0);
    descendants.resize(n + 1, 0);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(adj, 1, -1, 0);
    vector<int> happiness(n);
    for (int u = 1; u <= n; u++) happiness[u - 1] = depth[u] - descendants[u];
    sort(happiness.rbegin(), happiness.rend());
    long long ans = 0;
    for (int u = 0; u < k; u++) ans = ans + (long long)happiness[u];
    cout << ans;
    cout << endl;
  }
}
