#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power_mod(long long x, long long y, long long m) {
  long long arr = 1;
  x %= m;
  while (y) {
    if (y & 1) {
      arr = (arr * x) % m;
    }
    y >>= 1;
    x = (x * x) % m;
  }
  return arr;
}
long long power(long long x, long long y) {
  long long arr = 1;
  while (y) {
    if (y & 1) {
      arr *= x;
    }
    y >>= 1;
    x = x * x;
  }
  return arr;
}
long long mod_inv(long long x, long long m) { return power_mod(x, m - 2, m); }
int randomGenerator(int limit) {
  random_device rd;
  mt19937 gen(rd());
  uniform_int_distribution<> dis(1, limit);
  return dis(gen);
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
bool comp(const pair<long long, pair<long long, long long>> &a,
          const pair<long long, pair<long long, long long>> &b) {
  if (a.first == b.first) {
    return (a.second < b.second);
  }
  return (a.first < b.first);
}
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
bool isPalindrome(string s) {
  bool flag = true;
  for (int i = 0; i < s.length() / 2; i++) {
    if (s[i] != s[s.length() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<long long> adj[200005], dist(200005, 0), par(200005, 0), cost(200005, 0),
    subtree_size(200005, 0);
void dfs(long long node, long long p, long long len) {
  dist[node] = len;
  par[node] = p;
  subtree_size[node] = 0;
  for (long long child : adj[node]) {
    if (child != p) {
      dfs(child, node, len + 1);
      subtree_size[node] += (subtree_size[child] + 1);
    }
  }
  cost[node] = (dist[node] - subtree_size[node]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < (n); i++) {
    adj[i].clear();
    par[i] = 0;
    dist[i] = 0;
    cost[i] = 0;
    subtree_size[i] = 0;
  }
  for (long long i = 0; i < (n - 1); i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0, -1, 0);
  sort(cost.begin(), cost.begin() + n, greater<long long>());
  long long ans = 0;
  for (long long i = 0; i < (k); i++) {
    ans += cost[i];
  }
  cout << ans << "\n";
  return 0;
}
