#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353,INF=1e18;
#define ll long long
#define line cout<<"\n";
#define flush cout<<endl;
#define pll pair<ll,ll>
#define x first
#define y second
#define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n";
ll k,n;
vector<vector<ll> > tree;
ll cnt=0;
ll dfs(ll u,ll pa,ll num)
{
    ll ma1=0,ma2=0,mi=0;
    for(auto v:tree[u])
    {
        if(v!=pa)
        {
            ll temp=1LL+dfs(v,u,num);
            ma2=max(ma2,temp);
            mi=min(mi,temp);
            if(ma2>ma1)
            {
                swap(ma2,ma1);
            }
        }
    }
    if(mi<0&&abs(mi+1)>=ma1)
    {
        return mi;
    }
    if(ma1==num)
    {
        cnt++;
        ma1=-num-1;
    }
    else if(pa==-1)
    {
        if(ma1>=0)
        cnt++;
    }
    return ma1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll t=1;
    // cin>>t;
    for(ll test=1;test<=t;test++)
    {
        cin>>n>>k;
        tree.resize(n);
        for(int i=0;i<n-1;i++)
        {
            ll u,v;
            cin>>u>>v;
            u--,v--;
            tree[u].push_back(v);
            tree[v].push_back(u);
        }
        ll l=1,r=n;
        while(l<r)
        {
            ll m=(l+r)/2;
            cnt=0;
            ll count1=dfs(0,-1,m);
            if(cnt<=k)
            {
                r=m;
            }
            else
            {
                l=m+1;
            }
        }
        cout<<l<<"\n";
    }
    return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
//#define puts sdf
using std::vector;
//using std::cout;
//using std::endl;
using std::sort;
using std::swap;
using std::min;
using std::max;

int read(){//int 无负数 
	int h=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')h=(h<<1)+(h<<3)+c-'0',c=getchar();
	return h;
}

const int MAXN=200100;
int K,n;
struct Edge{
    int to;
    int nxt;
}edge[MAXN<<1];
int frm[MAXN];
int cnt_e;

void insert_e(int u,int v){
    cnt_e++;
    edge[cnt_e].to=v;
    edge[cnt_e].nxt=frm[u];
    frm[u]=cnt_e;
}
int Fa[MAXN];

int Rt,mns,S;
int siz[MAXN];
bool vis[MAXN];
void get_rt(int x,int ff){
    siz[x]=1;int mxs=0;
    for(int i=frm[x];i;i=edge[i].nxt){
        int v=edge[i].to;if(v==ff||vis[v])continue;
        get_rt(v,x);
        siz[x]+=siz[v];
        mxs=max(mxs,siz[v]);
    } 
    mxs=max(mxs,S-siz[x]);
    if(mxs<mns)Rt=x,mns=mxs;
} 

int Dt[MAXN];//点分树上的深度 
int dis[MAXN][21]; //x到点分树上深度为D的那个祖先的距离 
int mndis[MAXN];//距离他最近的点 

void get_dis1(int U,int x,int ff,int dep,int D){
    dis[x][D]=dep;
    for(int i=frm[x];i;i=edge[i].nxt){
        int v=edge[i].to;if(v==ff||vis[v])continue;
        get_dis1(U,v,x,dep+1,D);
    }
}

void divide(int x,int D){//D是点分树上的深度 
    vis[x]=true;
    Dt[x]=D;
    get_dis1(x,x,x,0,D);
    for(int i=frm[x];i;i=edge[i].nxt){
        int v=edge[i].to;if(vis[v])continue;

        S=siz[v],mns=siz[v],get_rt(v,v);
        Fa[Rt]=x;divide(Rt,D+1);
    }
}

void Modify(int x){
    int rt=x;
    for(;rt;rt=Fa[rt]){
        mndis[rt]=min(mndis[rt],dis[x][Dt[rt]]);
//        cout<<"MODIFY"<<x<<" "<<rt<<" "<<mndis[rt]<<endl;
    }
}

bool Query(int x,int mid){
    int rt=x;
    for(;rt;rt=Fa[rt]){
//    	cout<<"QUERY "<<x<<' '<<rt<<" "<<mndis[rt]<<' '<<dis[x][Dt[rt]]<<endl;
        if(mndis[rt]+dis[x][Dt[rt]]<=mid)return true;
    }
    return false;
}

int fa[MAXN][19];
int dep[MAXN];
int qwq[MAXN];//按深度排序 
bool cmp(int x,int y){
	return dep[x]>dep[y];
}
void pre_dfs(int x,int ff){
	fa[x][0]=ff;dep[x]=dep[ff]+1;
	for(int i=1;i<=18;i++)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=frm[x];i;i=edge[i].nxt){
		int v=edge[i].to;if(v==ff)continue;
		pre_dfs(v,x);
	}
}

int get_fa(int x,int k){
	int nw=x;
	for(int i=0;i<=18;i++){
		if(k&(1<<i))nw=fa[nw][i];
	}
	return nw;
}

bool ch_ck(int mid){
//	cout<<"MID"<<':'<<mid<<endl;
	memset(mndis,0x3f,sizeof(mndis));
//	for(int i=1;i<=n;i++)mndis[i]=-0x3f3f3f3f;
	int cnt=0;
	for(int i=1;i<=n;i++){
		int x=qwq[i];
		if(Query(x,mid))continue;
		int fk=get_fa(x,mid);
		cnt++;Modify(fk);
//		cout<<"WORK"<<x<<" "<<fk<<endl;
		if(cnt>K)return false;
	}
	return true;
}

int get_ans(){
	int l=0,r=n;
	while(l+1<r){
		int mid=(l+r)>>1;
		if(ch_ck(mid)){
			r=mid;
		}
		else l=mid+1;
	}
	if(l==r)return r;
	if(ch_ck(l))return l;
	return r;
}

int main(){
	n=read(),K=read();
    for(int i=1;i<=n-1;i++){
        int u=read(),v=read();
        insert_e(u,v),insert_e(v,u);
    }
    S=n,mns=n,get_rt(1,1);
    divide(Rt,0);
    pre_dfs(1,1);
    for(int i=1;i<=n;i++)qwq[i]=i;sort(qwq+1,qwq+n+1,cmp);
//    for(int i=1;i<=n;i++)cout<<qwq[i]<<" ";puts("");
//    for(int i=1;i<=n;i++){
//    	for(int j=0;j<=18;j++)cout<<fa[i][j]<<" ";puts("");
//	}
    printf("%d\n",get_ans());
	return 0;
}