#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b > a) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long expo(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}
vector<int> sieve(int n) {
  int *arr = new int[n + 1]();
  vector<int> vect;
  for (int i = 2; i <= n; i++)
    if (arr[i] == 0) {
      vect.push_back(i);
      for (int j = 2 * i; j <= n; j += i) arr[j] = 1;
    }
  return vect;
}
void extendgcd(long long a, long long b, long long *v) {
  if (b == 0) {
    v[0] = 1;
    v[1] = 0;
    v[2] = a;
    return;
  }
  extendgcd(b, a % b, v);
  long long x = v[1];
  v[1] = v[0] - v[1] * (a / b);
  v[0] = x;
  return;
}
long long mminv(long long a, long long b) {
  long long arr[3];
  extendgcd(a, b, arr);
  return arr[0];
}
long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }
bool compare(long long a, long long b) { return a > b; }
struct Node {
  int height;
  int nodes_below;
  int value;
};
int dfs(int start, Node *arr, vector<int> *edges, int height, bool *visited) {
  visited[start] = true;
  int sum = 0;
  for (int i = 0; i < edges[start].size(); i++) {
    if (visited[edges[start][i]] || edges[start][i] == start)
      continue;
    else {
      sum++;
      arr[edges[start][i]].nodes_below =
          dfs(edges[start][i], arr, edges, height, visited);
      sum += arr[edges[start][i]].nodes_below;
    }
  }
  return sum;
}
void bfs(int start, Node *arr, vector<int> *edges, int height, bool *visited) {
  arr[start].height = height;
  queue<int> qu;
  qu.push(start);
  while (!qu.empty()) {
    int top1 = qu.front();
    visited[top1] = true;
    qu.pop();
    for (int i = 0; i < edges[top1].size(); i++) {
      if (visited[edges[top1][i]])
        continue;
      else {
        qu.push(edges[top1][i]);
        arr[edges[top1][i]].height = arr[top1].height + 1;
        visited[edges[top1][i]] = true;
      }
    }
  }
}
void dfs1(int start, int *ans, vector<int> *edges, bool *arr1, bool *visited,
          int value) {
  visited[start] = true;
  if (arr1[start])
    ans[start] += value;
  else
    value++;
  for (int i = 0; i < edges[start].size(); i++) {
    if (visited[edges[start][i]] || edges[start][i] == start)
      continue;
    else
      dfs1(edges[start][i], ans, edges, arr1, visited, value);
  }
}
bool compare1(Node n1, Node n2) {
  if (n1.height - n1.nodes_below > n2.height - n2.nodes_below) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> *edges = new vector<int>[n]();
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  Node *arr = new Node[n];
  for (int i = 0; i < n; i++) {
    arr[i].height = 0;
    arr[i].nodes_below = 0;
    arr[i].value = i;
  }
  bool *visited = new bool[n]();
  arr[0].nodes_below = dfs(0, arr, edges, 0, visited);
  visited = new bool[n]();
  bfs(0, arr, edges, 0, visited);
  sort(arr, arr + n, compare1);
  bool *arr1 = new bool[n]();
  for (int i = 0; i < k; i++) {
    arr1[arr[i].value] = true;
  }
  int *ans = new int[n]();
  visited = new bool[n]();
  dfs1(0, ans, edges, arr1, visited, 0);
  long long sum_max = 0;
  for (int i = 0; i < n; i++) {
    sum_max += ans[i];
  }
  cout << sum_max << endl;
  return 0;
}
