#include<bits/stdc++.h> using namespace std; const int N=1e5+333; vector<int>v[N]; int dep1[N],dep2[N]; int maxd1,maxd2; int n; struct re{ int poi,val; bool operator <(const re &az)const{ return val<az.val; } }; priority_queue<re>s; int dfs1(int fath,int x){ dep1[x]=dep1[fath]+1; if(dep1[x]>dep1[maxd1])maxd1=x; for(int i=0;i<v[x].size();i++){ int dot=v[x][i]; if(dot==fath)continue; dfs1(x,dot); } } int dfs2(int fath,int x){ dep2[x]=dep2[fath]+1; if(dep2[x]>dep2[maxd2])maxd2=x; for(int i=0;i<v[x].size();i++){ int dot=v[x][i]; if(dot==fath)continue; dfs2(x,dot); } } int f[N]; int tr(int fath,int x){ for(int i=0;i<v[x].size();i++){ int dot=v[x][i]; if(dot==fath)continue; tr(x,dot); f[x]=max(f[x],f[dot]+1); } } int dist,vot,k,cnt; bool p[N]; int main(){ //freopen("p.in","r",stdin); //freopen("p.out","w",stdout); cin>>n>>k; if(n==k){cout<<0;return 0;} for(int i=1;i<n;i++){ int a,b; cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } dfs1(0,1); dfs2(0,maxd1); dist=dep2[maxd2]-1; for(int i=1;i<=n;i++){ int l=dep1[maxd1]-dep1[i]; if(dist/2==l){vot=i;break;} } tr(0,vot); re zl; for(int i=0;i<v[vot].size();i++){ int dot=v[vot][i]; zl.poi=dot;zl.val=f[dot]; s.push(zl); p[dot]=1; } cnt=0;p[vot]=1; while(cnt<k){ cnt++; zl=s.top(); s.pop(); int x=zl.poi; p[x]=1; for(int i=0;i<v[x].size();i++){ int dot=v[x][i]; if(p[dot])continue; zl.poi=dot;zl.val=f[dot]; s.push(zl); p[dot]=1; } } sort(f+1,f+1+n); cout<<f[n-k-1]+1; return 0; }