#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long int;
using ld = long double;
using namespace std;
using vll = vector<ll>;
struct Node {
  int depth = -1;
  int cntChild = -1;
  set<Node*> children;
  bool tourist = 0;
  void setDepth(int depth) {
    this->depth = depth;
    for (auto node = children.begin(); node != children.end();) {
      if ((*node)->depth != -1)
        node = children.erase(node);
      else {
        (*node)->setDepth(depth + 1);
        node++;
      }
    }
  }
  int calcChild() {
    cntChild = 0;
    for (Node* node : children) cntChild += node->calcChild();
    return cntChild + 1;
  }
  ll getAns() {
    if (!tourist) {
      return (1ll + cntChild) * depth;
    } else {
      ll ans = 0;
      for (Node* node : children) ans += node->getAns();
      return ans;
    }
  }
};
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(NULL);
  Node nodes[200000];
  int n, k;
  cin >> n >> k;
  int kk = n - k;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    nodes[u - 1].children.insert(nodes + v - 1);
    nodes[v - 1].children.insert(nodes + u - 1);
  }
  nodes[0].setDepth(0);
  nodes[0].calcChild();
  vector<Node*> nodescopy;
  for (int i = 0; i < n; i++) nodescopy.push_back(nodes + i);
  sort(nodescopy.begin(), nodescopy.end(), [](Node* x, Node* y) {
    return x->cntChild - x->depth > y->cntChild - y->depth;
  });
  for (int i = 0; i < kk; i++) nodescopy[i]->tourist = 1;
  cout << nodes[0].getAns() << endl;
}
