#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
using namespace std;
//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
// if (p == 0)
// return 1;
//
// ll halfpow = modPower(b, p / 2);
// ll toReturn = (halfpow * halfpow) % mod;
// if (p % 2)
// toReturn = (toReturn * b) % mod;
//
// return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
// if (p == 0)
// return 1;
// ll ans = fastPower(b, p / 2);
// ans = (ans * ans);
// if (p % 2 != 0)
// ans = (ans * b);
// return ans;
//}
//ll GcdRecursive(ll a, ll b) {
// if (b == 0) return a;
// return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
// ll val = GcdRecursive(a, b);
// ll tmp = ((a % mod) * (b % mod)) % mod;
// ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
// return finalVal;
//
//}
//ll LCM(ll a, ll b) {
// return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
// ll c = a - q * b;
// a = b;
// b = c;
//}
//ll GcdIterative(ll a, ll b) {
// while (b) move1step(a, b, a / b);
// return a;
//}
//
//void pre(ll n) {
//
// fact[0] = 1;
// inv[0] = 1;
//
// for (ll i = 1; i <= n; i++) {
// fact[i] = (i * fact[i - 1]) % mod;
// inv[i] = modPower(fact[i], mod - 2);
// arr[i] = modPower(i, mod - 2);
// }
//}
//
//ll npr(ll n, ll r) {
// return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
// return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
// memset(primes, 1, sizeof primes);
// primes[0] = primes[1] = false;
// for (int i = 2; i <= val; i++) {
// if (primes[i]) {
// for (int j = i * i; j <= val; j += i) {
// primes[j] = 0;
// }
// }
// }
//
//}
const ll mod = 1e9 + 7;
const ll N = 2e6 + 7;
const ll inf = 1e9 + 5;
ll n, k, a, b;
vector<ll> adjList[N];
vector<ll> allPaths;
bool visited[N] = {false};
void dfs(ll node, ll lvl){
ll counter = 0;
if (visited[node]) return;
visited[node] = 1;
for (auto child: adjList[node]){
if (!visited[child]){
counter++;
dfs(child, lvl + 1);
}
}
if (!counter){
allPaths.push_back(lvl + 1);
}
}
int main()
{
MohamedMotaz;
memset(visited, false, sizeof(visited));
cin >> n >> k;
f(i,0,n - 1){
cin >> a >> b;
adjList[a].push_back(b);
adjList[b].push_back(a);
}
dfs(1, 0);
sort(allPaths.begin(), allPaths.end());
//for (auto elem: allPaths) cout << elem << " ";cout << endl;
vector<ll> copy;
for (auto elem: allPaths) copy.push_back(elem);
while (k){
sort(copy.begin(), copy.end());
fr(i,copy.size() - 1, 0){
copy[i]--;
k--;
if (k <= 0) break;
}
}
sort(copy.begin(), copy.end());
//for (auto elem: copy) cout << elem << " ";cout << endl;
ll s = 0;
fr(i, allPaths.size() - 1, 0){
s += copy[i] * (allPaths[i] - copy[i]);
}
if (k > copy.size()) s -= copy.size() *(k - copy.size());
cout << max(s, (ll)0) << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1Z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AgICAgIH0KICAgIH0KICAgIGlmICghY291bnRlcil7CiAgICAgICAgYWxsUGF0aHMucHVzaF9iYWNrKGx2bCArIDEpOwogICAgfQp9CgppbnQgbWFpbigpCnsKICAgIE1vaGFtZWRNb3RhejsKICAgIG1lbXNldCh2aXNpdGVkLCBmYWxzZSwgc2l6ZW9mKHZpc2l0ZWQpKTsKICAgIGNpbiA+PiBuID4+IGs7CiAgICBmKGksMCxuIC0gMSl7CiAgICAgICAgY2luID4+IGEgPj4gYjsKICAgICAgICBhZGpMaXN0W2FdLnB1c2hfYmFjayhiKTsKICAgICAgICBhZGpMaXN0W2JdLnB1c2hfYmFjayhhKTsKICAgIH0KICAgIGRmcygxLCAwKTsKICAgIHNvcnQoYWxsUGF0aHMuYmVnaW4oKSwgYWxsUGF0aHMuZW5kKCkpOwogICAgLy9mb3IgKGF1dG8gZWxlbTogYWxsUGF0aHMpIGNvdXQgPDwgZWxlbSA8PCAiICI7Y291dCA8PCBlbmRsOwogICAgdmVjdG9yPGxsPiBjb3B5OwogICAgZm9yIChhdXRvIGVsZW06IGFsbFBhdGhzKSBjb3B5LnB1c2hfYmFjayhlbGVtKTsKCiAgICB3aGlsZSAoayl7CiAgICAgICAgc29ydChjb3B5LmJlZ2luKCksIGNvcHkuZW5kKCkpOwogICAgICAgIGZyKGksY29weS5zaXplKCkgLSAxLCAwKXsKICAgICAgICAgICAgY29weVtpXS0tOwogICAgICAgICAgICBrLS07CiAgICAgICAgICAgIGlmIChrIDw9IDApIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIHNvcnQoY29weS5iZWdpbigpLCBjb3B5LmVuZCgpKTsKICAgIC8vZm9yIChhdXRvIGVsZW06IGNvcHkpIGNvdXQgPDwgZWxlbSA8PCAiICI7Y291dCA8PCBlbmRsOwogICAgbGwgcyA9IDA7CiAgICBmcihpLCBhbGxQYXRocy5zaXplKCkgLSAxLCAwKXsKCiAgICAgICAgICAgIHMgKz0gY29weVtpXSAqIChhbGxQYXRoc1tpXSAtIGNvcHlbaV0pOwoKICAgIH0KICAgIGlmIChrID4gY29weS5zaXplKCkpIHMgLT0gY29weS5zaXplKCkgKihrIC0gY29weS5zaXplKCkpOwogICAgY291dCA8PCBtYXgocywgKGxsKTApIDw8IGVuZGw7Cgp9CgoKCg==