#include <bits/stdc++.h>
using namespace std;
bool LT(double a, double b) { return !(fabs((a) - (b)) < (1e-9)) && a < b; }
bool LTE(double a, double b) { return (fabs((a) - (b)) < (1e-9)) || a < b; }
int n, k;
vector<int> G[200010];
int mini[200010];
int deg[200010];
struct Data {
  int cur;
  bool operator<(const Data &d) const {
    long long v1 =
        (long long)mini[cur] - (long long)((long long)deg[cur] - 1LL);
    long long v2 =
        (long long)mini[d.cur] - (long long)((long long)deg[d.cur] - 1LL);
    if (v1 != v2) return v1 < v2;
    return cur < d.cur;
  }
  long long calc() {
    return (long long)mini[cur] - (long long)((long long)deg[cur] - 1LL);
  }
};
void calc_mini() {
  for (int i = 0; i < n; ++i) mini[i] = INT_MAX;
  mini[0] = 0;
  deque<int> deq;
  deq.push_back(0);
  while (!deq.empty()) {
    int cur = deq.front();
    deq.pop_front();
    for (int i = 0; i < (int)G[cur].size(); ++i) {
      int nex = G[cur][i];
      if (mini[nex] != INT_MAX) continue;
      mini[nex] = mini[cur] + 1;
      deq.push_back(nex);
    }
  }
}
long long dfs(int cur, int prev) {
  long long sum = 1;
  for (int i = 0; i < (int)G[cur].size(); ++i) {
    int nex = G[cur][i];
    if (nex == prev) continue;
    sum += dfs(nex, cur);
  }
  return deg[cur] = sum;
}
struct Fack {
  int cur, depth;
  bool operator<(const Fack &f) const {
    if (depth != f.depth) return depth < f.depth;
    return cur < f.cur;
  }
};
void calc_deg() {
  memset(deg, 0, sizeof deg);
  set<int> S;
  priority_queue<Fack> deq;
  for (int i = 0; i < n; ++i)
    if (G[i].size() == 1) {
      deq.push((Fack){i, mini[i]});
      S.insert(i);
    }
  for (int i = 0; i < n; ++i) deg[i] = 1;
  while (!deq.empty()) {
    Fack tmp = deq.top();
    deq.pop();
    int cur = tmp.cur;
    for (int i = 0; i < (int)G[cur].size(); ++i) {
      int nex = G[cur][i];
      if (mini[nex] >= mini[cur]) continue;
      deg[nex] += deg[cur];
      if (S.count(nex) == 0) {
        S.insert(nex);
        deq.push((Fack){nex, mini[nex]});
      }
    }
  }
}
bool used[200010];
void solve() {
  calc_mini();
  calc_deg();
  long long sum = 0;
  priority_queue<Data> Q;
  for (int i = 0; i < n; ++i)
    if (G[i].size() == 1) {
      Q.push((Data){i});
    }
  memset(used, false, sizeof used);
  int cnt = 0;
  while (cnt < k) {
    Data d = Q.top();
    Q.pop();
    sum += d.calc();
    used[d.cur] = true;
    for (int i = 0; i < (int)G[d.cur].size(); ++i) {
      int nex = G[d.cur][i];
      if (!used[nex]) {
        used[nex] = true;
        Q.push((Data){nex});
      }
    }
    ++cnt;
  }
  cout << sum << endl;
}
int main() {
  if (0) {
    int n = 200000;
    cout << n << " " << 1 << endl;
    for (int i = 0; i < n - 1; ++i) {
      cout << i + 1 << " " << i + 2 << endl;
    }
    return 0;
  }
  scanf("%d%d", &n, &k);
  int s, t;
  for (int _ = 0; _ < n - 1; ++_) {
    scanf("%d%d", &s, &t);
    --s, --t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  solve();
  return 0;
}
