//******************************** JAI SAI RAM ****************************************//
//help me in codeforces round 635 div2
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
const int sizes=400001,block=700;
ll P=1000000007;
ll MAX=10000*P;
ll MIN=-1*MAX;
vector<ll> adj[100001];
ll parent[100001];
ll vis[100001];
ll counts[100001];
vector<ll> levels[sizes];
void count_nodes(ll src,ll e)
{
counts[src]=1;
for(ll i=0;i<adj[src].size();i++)
{
ll v=adj[src][i];
if(v==e)
{
continue;
}
count_nodes(v,src);
counts[src]+=counts[v];
}
}
void dfs(ll src,ll level)
{
vis[src]=1;
levels[level].push_back(src);
for(ll i=0;i<adj[src].size();i++)
{
if(!vis[adj[src][i]])
{
parent[adj[src][i]]=src;
dfs(adj[src][i],level+1);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t,n,i,j,k,l,m,o,p,q,r,s,a[sizes];
//cin>>t;
t=1;
while(t--)
{
string ss;
vector<ll> v;
//ll ans=0;
ll kk;
cin>>n>>kk;
memset(counts,0,sizeof(ll)*(n+1));
memset(vis,0,sizeof(ll)*(n+1));
memset(parent,0,sizeof(ll)*(n+1));
for(i=1;i<=n;i++)
{
levels[i].clear();
adj[i].clear();
}
for(i=0;i<n-1;i++)
{
cin>>j>>k;
adj[j].push_back(k);
adj[k].push_back(j);
}
count_nodes(1,0);
dfs(1,1);
ll ans=0;
l=0;
k=kk;
vector<ll> se;
for(i=n;i>=1;i--)
{
for(j=0;j<levels[i].size();j++)
{
se.push_back((i-1)-(counts[levels[i][j]]-1));
}
}
// cout<<se.size()<<endl;
sort(se.begin(),se.end());
l=0;
for(i=se.size()-1;i>=0;i--)
{
//cout<<se[i]<<" ";
if(l>=k)
break;
l++;
ans+=se[i];
}
cout<<ans<<endl;
}
return 0;
}
Ly8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiBKQUkgU0FJIFJBTSAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLy8KLy9oZWxwIG1lIGluIGNvZGVmb3JjZXMgcm91bmQgNjM1IGRpdjIKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwojZGVmaW5lIGVuZGwgIlxuIgpjb25zdCBpbnQgc2l6ZXM9NDAwMDAxLGJsb2NrPTcwMDsKCmxsIFA9MTAwMDAwMDAwNzsKbGwgTUFYPTEwMDAwKlA7CmxsIE1JTj0tMSpNQVg7CiAgICB2ZWN0b3I8bGw+IGFkalsxMDAwMDFdOwogICAgbGwgcGFyZW50WzEwMDAwMV07CiAgICBsbCB2aXNbMTAwMDAxXTsKICAgIGxsIGNvdW50c1sxMDAwMDFdOwogICAgdmVjdG9yPGxsPiBsZXZlbHNbc2l6ZXNdOwoKdm9pZCBjb3VudF9ub2RlcyhsbCBzcmMsbGwgZSkKICAgIHsKICAgICAgICBjb3VudHNbc3JjXT0xOwogICAgICAgIGZvcihsbCBpPTA7aTxhZGpbc3JjXS5zaXplKCk7aSsrKQogICAgICAgIHsKICAgICAgICAgICAgbGwgdj1hZGpbc3JjXVtpXTsKICAgICAgICAgICAgaWYodj09ZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY291bnRfbm9kZXModixzcmMpOwogICAgICAgICAgIGNvdW50c1tzcmNdKz1jb3VudHNbdl07CiAgICAgICAgfQogICAgfQogICAKICB2b2lkIGRmcyhsbCBzcmMsbGwgbGV2ZWwpCiAgewogICAgdmlzW3NyY109MTsKICAgIGxldmVsc1tsZXZlbF0ucHVzaF9iYWNrKHNyYyk7CiAgICBmb3IobGwgaT0wO2k8YWRqW3NyY10uc2l6ZSgpO2krKykKICAgIHsKICAgICAgICBpZighdmlzW2FkaltzcmNdW2ldXSkKICAgICAgICB7CiAgICAgICAgICAgIHBhcmVudFthZGpbc3JjXVtpXV09c3JjOyAKICAgICAgICAgICAgZGZzKGFkaltzcmNdW2ldLGxldmVsKzEpOwogICAgICAgIH0KICAgIH0KICB9CmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKDApOwogICAgbGwgdCxuLGksaixrLGwsbSxvLHAscSxyLHMsYVtzaXplc107CiAgICAvL2Npbj4+dDsKICAgIHQ9MTsKICAgIHdoaWxlKHQtLSkKICAgIHsKICAgIHN0cmluZyBzczsKICAgIHZlY3RvcjxsbD4gdjsKICAgIC8vbGwgYW5zPTA7CiAgICBsbCBrazsKICAgIGNpbj4+bj4+a2s7CiAgICBtZW1zZXQoY291bnRzLDAsc2l6ZW9mKGxsKSoobisxKSk7CiAgICBtZW1zZXQodmlzLDAsc2l6ZW9mKGxsKSoobisxKSk7CiAgICBtZW1zZXQocGFyZW50LDAsc2l6ZW9mKGxsKSoobisxKSk7CiAgICBmb3IoaT0xO2k8PW47aSsrKQogICAgewogICAgICAgIGxldmVsc1tpXS5jbGVhcigpOwogICAgICAgIGFkaltpXS5jbGVhcigpOwogICAgfQogICAgZm9yKGk9MDtpPG4tMTtpKyspCiAgICB7CiAgICAgICAgY2luPj5qPj5rOwogICAgICAgIGFkaltqXS5wdXNoX2JhY2soayk7CiAgICAgICAgYWRqW2tdLnB1c2hfYmFjayhqKTsKICAgIH0KICAgIAogICAgY291bnRfbm9kZXMoMSwwKTsKICAgIGRmcygxLDEpOwogICAgbGwgYW5zPTA7CiAgICBsPTA7CiAgaz1razsKICAgIHZlY3RvcjxsbD4gc2U7CiAgICBmb3IoaT1uO2k+PTE7aS0tKQogICAgewogICAgICAgIGZvcihqPTA7ajxsZXZlbHNbaV0uc2l6ZSgpO2orKykKICAgICAgICB7CiAgICAgICAgICAgCiAgICAgICAgICAgICBzZS5wdXNoX2JhY2soKGktMSktKGNvdW50c1tsZXZlbHNbaV1bal1dLTEpKTsKICAgICAgICB9CiAgICAgICAgCiAgICB9CiAgIC8vIGNvdXQ8PHNlLnNpemUoKTw8ZW5kbDsKICAgIHNvcnQoc2UuYmVnaW4oKSxzZS5lbmQoKSk7CiAgICBsPTA7CiAgICBmb3IoaT1zZS5zaXplKCktMTtpPj0wO2ktLSkKICAgIHsKICAgICAgICAgIC8vY291dDw8c2VbaV08PCIgIjsKICAgICAgICAgIGlmKGw+PWspCiAgICAgICAgICBicmVhazsKICAgICAgICAgIGwrKzsKICAgICAgICAgIGFucys9c2VbaV07CiAgICB9CiAgICBjb3V0PDxhbnM8PGVuZGw7CiAgfQogICAgcmV0dXJuIDA7Cn0=