#include <bits/stdc++.h>
using namespace std;
const int Max = 2e5 + 10;
int n, k;
int v, u;
vector<int> stl[Max];
struct node {
  long long cou;
  long long huo;
  node() { cou = huo = 0; }
} point[Max];
int vis[Max];
long long tot = 0;
void dfs(int idex, int cou) {
  vis[idex] = 1;
  point[idex].cou = cou;
  int flag = 0;
  for (int i = 0; i < stl[idex].size(); i++) {
    if (vis[stl[idex][i]] == 0) {
      dfs(stl[idex][i], cou + 1);
      flag = 1;
    }
  }
  if (!flag) {
    point[idex].huo = 1;
    return;
  }
  for (int i = 0; i < stl[idex].size(); i++)
    point[idex].huo += point[stl[idex][i]].huo;
  point[idex].huo++;
}
long long ans[Max];
int main() {
  cin >> n >> k;
  int flag = 1;
  for (int i = 1; i <= n - 1; i++) {
    cin >> v >> u;
    stl[v].push_back(u);
    stl[u].push_back(v);
  }
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    ans[i] = point[i].cou - point[i].huo;
  }
  sort(ans + 1, ans + n + 1);
  for (int i = n; i > n - k; i--) {
    tot += ans[i];
  }
  cout << tot << endl;
  return 0;
}
