#include <bits/stdc++.h>
using namespace std;
template <typename T, typename second>
ostream& operator<<(ostream& s, pair<T, second>& p) {
  s << '{' << p.first << ", " << p.second << '}';
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
  if (v.empty()) {
    s << "[]";
    return s;
  }
  s << '[';
  for (int i = 0; i < v.size() - 1; i++) s << v[i] << ", ";
  s << v.back() << ']';
  return s;
}
int n, k;
vector<vector<int>> verts;
vector<int> adj[200005];
int a, b;
bool ind[200005];
uint64_t ans = 0;
int dfs1(int st, int pr, int h) {
  int sm = 1;
  for (auto x : adj[st]) {
    if (x != pr) sm += dfs1(x, st, h + 1);
  }
  verts.push_back({h - sm, st});
  return sm;
}
int dfs2(int st, int pr) {
  int sm = ind[st];
  for (auto x : adj[st]) {
    if (x != pr) {
      sm += dfs2(x, st);
    }
  }
  if (!ind[st]) {
    ans += sm;
  }
  return sm;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs1(1, 0, 0);
  sort(verts.begin(), verts.end());
  for (int i = 0; i < k; i++) {
    auto ar = verts.back();
    ind[ar[1]] = true;
    verts.pop_back();
  }
  dfs2(1, 0);
  printf("%llu\n", ans);
  return 0;
}
