#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  T x = 0;
  char ch = getchar();
  bool f = 0;
  while (!isdigit(ch)) {
    f = (ch == '-');
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return f ? -x : x;
}
template <typename T>
void put(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x < 10) {
    putchar(x + 48);
    return;
  }
  put(x / 10);
  putchar(x % 10 + 48);
  return;
}
const int Maxn = 2e5 + 111;
int h[Maxn], cnt, n, dis[Maxn], num[Maxn], fa[Maxn], k, sz[Maxn];
long long ans;
struct cmp {
  bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
    return a.second < b.second;
  }
};
vector<int> edge[Maxn];
inline void add_edge(int x, int y) {
  edge[x].push_back(y);
  edge[y].push_back(x);
}
priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> Q;
void dfs(int u, int f) {
  fa[u] = f;
  dis[u] = dis[f] + 1;
  sz[u] = 1;
  for (auto &i : edge[u]) {
    if (f == i) continue;
    dfs(i, u);
    sz[u] += sz[i];
  }
  if (sz[u] == 1) num[u]++, Q.push(make_pair(u, dis[u]));
  return void();
}
int main() {
  n = read<int>();
  k = read<int>();
  memset(h, -1, sizeof h);
  for (int i = 1; i < n; ++i) add_edge(read<int>(), read<int>());
  dis[0] = -1;
  dfs(1, 0);
  while (k--) {
    pair<int, int> tp = Q.top();
    Q.pop();
    ans += tp.second;
    num[fa[tp.first]] += num[tp.first];
    if (num[fa[tp.first]] == sz[fa[tp.first]] - 1)
      Q.push(make_pair(fa[tp.first], dis[fa[tp.first]] - num[fa[tp.first]])),
          num[fa[tp.first]]++;
  }
  put<long long>(ans);
  return 0;
}
