#include <bits/stdc++.h>
using namespace std;
void fs(long long int &number) {
  bool negative = false;
  register long long int c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
}
long long int power(long long int a, long long int x) {
  a %= 1000000007;
  long long int res = 1;
  while (x > 0) {
    if (x & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    x >>= 1;
  }
  return res;
}
long long int max(long long int a, long long int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long int madd(long long int a, long long int b) {
  long long int ans;
  ans = (a % 1000000007 + b % 1000000007) % 1000000007;
  return ans;
}
long long int mmult(long long int a, long long int b) {
  long long int ans = 1;
  ans = ((a % 1000000007) * (b % 1000000007)) % 1000000007;
  return ans % 1000000007;
}
long long int modinverse(long long int a) { return power(a, 1000000007 - 2); }
vector<long long int> v[200005];
long long int subtree[200005], visit[200005], val[200005], level[200005],
    industry[200005];
vector<pair<pair<long long int, long long int>, long long int>> pr;
long long int ans = 0;
void dfs(long long int s) {
  visit[s] = 1;
  subtree[s] = 1;
  for (long long int i = 0; i < v[s].size(); i++) {
    if (visit[v[s][i]] == 0) {
      level[v[s][i]] = level[s] + 1;
      dfs(v[s][i]);
      subtree[s] += subtree[v[s][i]];
    }
  }
}
void dfs2(long long int s) {
  visit[s] = 1;
  if (industry[s] == 1) {
    val[s]++;
  }
  for (long long int i = 0; i < v[s].size(); i++) {
    if (visit[v[s][i]] == 0) {
      val[v[s][i]] += val[s];
      dfs2(v[s][i]);
    }
  }
}
bool srt(pair<long long int, long long int> p1,
         pair<long long int, long long int> p2) {
  return (p1.first > p2.first);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int k, n;
  cin >> n >> k;
  for (long long int i = 1; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1);
  vector<pair<long long int, long long int>> vx;
  for (long long int i = 1; i <= n; i++) {
    val[i] = (level[i] - subtree[i] + 1);
    vx.push_back({val[i], i});
  }
  for (long long int i = 1; i <= n; i++) {
    industry[i] = 1;
  }
  long long int count = 0;
  sort(vx.begin(), vx.end(), srt);
  for (long long int i = 0; i < vx.size(); i++) {
    industry[vx[i].second] = -1;
    count++;
    if (count == k) {
      break;
    }
  }
  for (long long int i = 0; i <= n; i++) {
    val[i] = 0;
    visit[i] = 0;
  }
  dfs2(1);
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    if (industry[i] == -1) {
      sum += val[i];
    }
  }
  cout << sum;
  cout << "\n";
}
