#include <bits/stdc++.h>
using namespace std;
vector<int> graph[(int)2e5 + 5];
int visited[(int)2e5 + 5];
vector<int64_t> values;
int64_t dfs(int node, int depth) {
  if (visited[node] == 1) return 0;
  visited[node] = 1;
  int64_t child = 0;
  for (int i = 0; i < graph[node].size(); i++) {
    if (visited[graph[node][i]] == 0) child += dfs(graph[node][i], depth + 1);
  }
  values.push_back(depth - (int64_t)child);
  return child + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    int total_city, num_of_industry, u, v;
    cin >> total_city >> num_of_industry;
    for (int i = 1; i < total_city; i++) {
      cin >> u >> v;
      graph[u].push_back(v);
      graph[v].push_back(u);
    }
    dfs(1, 0);
    sort(values.begin(), values.end(), greater<int>());
    int64_t sum = 0;
    for (int i = 0; i < num_of_industry; i++) {
      sum += values[i];
    }
    cout << sum;
  }
  return 0;
}
