#include <bits/stdc++.h>
using namespace std;
int dist[200000];
bool distCheck[200000];
int below[200000];
bool belowCheck[200000];
pair<int, int> sortDist[200000];
bool sortFirst(pair<int, int> p1, pair<int, int> p2) {
  return (p1.first > p2.first);
}
void fillDist(vector<vector<int>> tree) {
  queue<int> inNodes;
  inNodes.push(0);
  while (!inNodes.empty()) {
    int node = inNodes.front();
    for (int i : tree[node]) {
      if (distCheck[i]) {
        continue;
      }
      inNodes.push(i);
      dist[i] = (dist[node] + 1);
      distCheck[i] = true;
    }
    inNodes.pop();
  }
  for (int i = 0; i < tree.size(); ++i) {
    sortDist[i].first = dist[i];
    sortDist[i].second = i;
  }
  sort(sortDist, sortDist + tree.size(), sortFirst);
}
void fillBelow(vector<vector<int>> tree) {
  queue<int> inNodes;
  inNodes.push(sortDist[1].second);
  belowCheck[sortDist[0].second] = true;
  below[sortDist[0].second] = 0;
  int i = 2;
  while (!inNodes.empty()) {
    int node = inNodes.front();
    if (belowCheck[node]) {
      inNodes.pop();
      continue;
    }
    int sum = 0;
    for (int i = 0; i < tree[node].size(); ++i) {
      if (dist[tree[node][i]] < dist[node]) {
        continue;
      }
      ++sum;
      sum += below[tree[node][i]];
    }
    below[node] = sum;
    belowCheck[node] = true;
    if (i < tree.size()) {
      inNodes.push(sortDist[i].second);
      ++i;
    }
    inNodes.pop();
  }
}
bool sortDif(pair<int, int> p1, pair<int, int> p2) {
  return (p1.first - p1.second) > (p2.first - p2.second);
}
int main() {
  int n, k;
  cin >> n >> k;
  dist[0] = 0;
  distCheck[0] = true;
  vector<vector<int>> tree(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    tree[a - 1].push_back(b - 1);
    tree[b - 1].push_back(a - 1);
  }
  fillDist(tree);
  fillBelow(tree);
  vector<pair<int, int>> amtSort(n);
  for (int i = 0; i < n; ++i) {
    amtSort[i].first = dist[i];
    amtSort[i].second = below[i];
  }
  sort(amtSort.begin(), amtSort.end(), sortDif);
  long long sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += (amtSort[i].first);
    sum -= amtSort[i].second;
  }
  cout << sum << endl;
}
