#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<vector<int> > v(N);
vector<long long> ans;
vector<bool> visited(N, false);
vector<int> sz(N, 1);
void dfs1(int x, int seen) {
  visited[x] = true;
  for (int y : v[x]) {
    if (!visited[y]) {
      ans.push_back(seen - sz[y] + 1);
      dfs1(y, seen + 1);
    }
  }
}
void dfs2(int x) {
  visited[x] = true;
  if (v[x].size() <= 1) sz[x] = v[x].size();
  for (int y : v[x]) {
    if (!visited[y]) {
      dfs2(y);
      sz[x] += sz[y];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  visited[0] = true;
  for (int x : v[0]) {
    if (!visited[x]) dfs2(x);
    sz[0] += sz[x];
  }
  for (int i = 1; i < n; i++) {
    visited[i] = false;
  }
  ans.push_back(0 - sz[0] + 1);
  for (int x : v[0]) {
    if (!visited[x]) {
      ans.push_back(1 - sz[x] + 1);
      dfs1(x, 2);
    }
  }
  sort(ans.rbegin(), ans.rend());
  long long solve = 0;
  for (int i = 0; i < k; i++) {
    solve += ans[i];
  }
  cout << solve << endl;
  return 0;
}
