#include <bits/stdc++.h>
using namespace std;
#define int long long
const int nax=2e5+100;
vector<int> g[nax];
int cnt,res,n,k,md;
int dfs(int s,int pp)
{
    int p=0;
    for(auto it:g[s])
    if(it^pp)
    {
        int q=dfs(it,s);
        if(q<p)
        swap(p,q);
        if(p<=0 and q>0 and q-p<=md)
        p=q;
    }
    if(p==-md)
    {
        cnt++;
        return 1;
    }
    if(p<=0)
    return p-1;
    return p+1;
}
bool find()
{
    cnt=0;
    cnt+=dfs(1,0)<0;
    return cnt<=k;
}
int32_t main()
{
    cnt=res=0;
    cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int l=1,r=n;
    while(l<=r)
    {
        md=(l+r)>>1;
        if(find())
        {
            res=md;
            r=md-1;
        }
        else
        l=md+1;
    }
    cout<<res;
    return 0;
}
#include<bits/stdc++.h>
#define fgx cerr<<"-----------------------"<<endl
#define LL long long
#define DB double
#define pb push_back
using namespace std;
inline int read(){
	int nm=0,fh=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') fh=-1;
	for(;isdigit(c);c=getchar()) nm=nm*10+c-'0';
	return nm*fh;
}
#define M 200020
#define pii pair<int,int>
#define mp make_pair
#define ds second
int n,K,ans,tot,to[M<<1],nt[M<<1],fs[M],dep[M],fa[M][21],lim;
bool vis[M]; priority_queue<pii >que;
inline void link(int u,int v){to[++tot]=v,nt[tot]=fs[u],fs[u]=tot;}
inline int Jump(int u,int k){for(int i=20;~i;i--) if(k&(1<<i)) u=fa[u][i]; return u;}
inline void dfs(int u,int last=0){
	dep[u]=dep[last]+1,fa[u][0]=last;
	for(int i=1;i<=20;i++) fa[u][i]=fa[fa[u][i-1]][i-1];
	for(int i=fs[u];i;i=nt[i]) if(to[i]^last) dfs(to[i],u);
}
inline void dfst(int u,int dep,int last=0){
	if(dep>lim) return; vis[u]=true;
	for(int i=fs[u];i;i=nt[i]) if(to[i]^last) dfst(to[i],dep+1,u);
}
inline bool Jud(int td){
	lim=td;
	for(int i=1;i<=n;i++) que.push(mp(dep[i],i)),vis[i]=false;
	int ret=0;	
	while(!que.empty()){
		if(ret>=K) return 0;
		int u=que.top().ds,pos; que.pop();
		if(vis[u]) continue;
		if(dep[u]<=td) pos=1; else pos=Jump(u,td);
		dfst(pos,0),ret++;
		while(!que.empty()&&vis[que.top().ds]) que.pop();
	} return ret<=K;
}
int main(){
	n=read(),ans=n; K=read();
	for(int i=1;i<n;i++){int u=read(),v=read(); link(u,v),link(v,u);}
	dfs(1);
	for(int k=20;~k;k--){int td=ans-(1<<k); if(td>=0&&Jud(td)) ans=td;}
	printf("%d\n",ans);
	return 0;
}