#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
vector<int> nopath = {-1};
set<int> leaves;
bool visited[MAX] = {0};
vector<int> distances(MAX + 1, 0);
vector<int> parents(MAX + 1, 0);
vector<int> lensubtree(MAX + 1, 0);
vector<int> adj[MAX];
void dfs() {
  vector<int> q;
  visited[1] = true;
  q.push_back(1);
  visited[1] = true;
  while (!q.empty()) {
    int cur;
    cur = q.back();
    q.pop_back();
    for (int j = 0; j < adj[cur].size(); j++) {
      int next = adj[cur][j];
      parents[next] = cur;
      if (adj[cur].size() == 1) leaves.insert(cur);
      if (!visited[next]) {
        visited[next] = true;
        distances[next] = distances[cur] + 1;
        q.push_back(next);
      }
    }
  }
  return;
}
void subtreesize(int s, int e) {
  vector<int>::iterator u;
  lensubtree[s] = 1;
  for (u = adj[s].begin(); u != adj[s].end(); u++) {
    if (*u == e) continue;
    subtreesize(*u, s);
    lensubtree[s] += lensubtree[*u];
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs();
  subtreesize(1, 0);
  long long answer = 0;
  vector<int> answervector;
  for (int i = 1; i < n + 1; i++)
    answervector.push_back(distances[i] - lensubtree[i] + 1);
  sort(answervector.begin(), answervector.end(), greater<int>());
  for (int i = 0; i < k; i++) answer += answervector[i];
  cout << answer;
}
