#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
	int a=0,fh=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	while('0'<=c&&c<='9'){
		a=a*10+c-48;
		c=getchar();
	}
	return a*fh;
}
#define MN 200005
#define pii pair<int,int>
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define vc vector
int n,k;
int id[MN],DEP[MN],dep[MN],fa[MN],w[MN],sec[MN];
int vis[MN],dfn[MN],cnt,ID[MN],siz[MN];
bool cmp(int a,int b){return dep[a]<dep[b];}
vector<int>e[MN];
void dfs(int x){
	dfn[x]=++cnt;
	ID[cnt]=x;
	dep[x]=dep[fa[x]]+1;
	siz[x]=1;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(fa[x]==v)continue;
		fa[v]=x;dfs(v);
		if(DEP[v]>DEP[w[x]]){
			sec[x]=DEP[w[x]]+1;
			w[x]=v;
		}
		else sec[x]=max(sec[x],DEP[v]+1);
		siz[x]+=siz[v];
	}
	DEP[x]=DEP[w[x]]+1;
}
int mid,st[MN],top,FA[MN];
void DFS(int x){
	st[++top]=x;
	if(dep[x]>mid)FA[x]=st[top-mid];
	else FA[x]=1;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(fa[x]==v)continue;
		DFS(v);
	}
	top--;
}
int mx[MN<<2];
#define Ls (x<<1)
#define Rs (x<<1|1)
void pushup(int x){
	mx[x]=max(mx[Ls],mx[Rs]);
}
void build(int x,int l,int r){
	if(l==r){mx[x]=dep[ID[l]];return;}
	int mid=l+r>>1;
	build(Ls,l,mid);
	build(Rs,mid+1,r);
	pushup(x);
}
void del(int x,int l,int r,int loc){
	if(l==r){mx[x]=0;return;}
	int mid=l+r>>1;
	if(loc<=mid)del(Ls,l,mid,loc);
	else del(Rs,mid+1,r,loc);
	pushup(x);
}
int ask(int x,int l,int r,int b,int e){
	if(b<=l&&r<=e)return mx[x];
	if(l>e||r<b)return 0;
	int mid=l+r>>1;
	if(e<=mid)return ask(Ls,l,mid,b,e);
	if(b>mid)return ask(Rs,mid+1,r,b,e);
	return max(ask(Ls,l,mid,b,e),ask(Rs,mid+1,r,b,e));
}
void fk(int x){
	if(vis[x])return;
	del(1,1,n,dfn[x]);
	vis[x]=1;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(fa[x]==v)continue;
		if(!vis[v]){
			fk(v);	
		}
	}
}
bool chk(){
	build(1,1,n);
	DFS(1);	
	for(int i=1;i<=n;++i)vis[i]=0;
	int tot=0;
	for(int i=1;i<=n;++i){
		int x=id[i];
		if(!vis[x]){
			tot++;
			int u=FA[x],t=mid;
			fk(u);
			while(t&&fa[u]&&ask(1,1,n,dfn[fa[u]],dfn[fa[u]]+siz[fa[u]]-1)-dep[fa[u]]+1<=t){
				t--;u=fa[u];
				fk(u);
			}	
		}
	}
	return tot<=k;
}
signed main(){
	n=read();k=read();
	for(int i=1;i<n;++i){
		int u=read(),v=read();
		e[u].pb(v);e[v].pb(u);
	}
	dfs(1);for(int i=1;i<=n;++i)id[i]=i;
	sort(id+1,id+1+n,cmp);reverse(id+1,id+1+n);
	int l=-1,r=n;
	while(l+1<r){
		mid=(l+r)>>1;
		if(chk())r=mid;
		else l=mid;
	}
	printf("%lld\n",r);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(v) int((v).size())
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define int ll

int n, k;
vector<int> tree[222'222];
int cnt = 0;
int dfs(int now, int before, int U)
{
    int x = 0;
    for (int nxt: tree[now])
    {
        if (nxt == before) continue;
        int y = dfs(nxt, now, U);
        if (x > y) swap(x, y);
        if (x <= 0 && y > 0 && y - x <= U)
            x = y;
    }
    if (x == -U)
    {
        ++cnt;
        x = 1;
    }
    else if (x <= 0)
    {
        --x;
    }
    else ++x;
    return x;
}
bool test(int U)
{
    cnt = 0;
    int cur = dfs(0, 0, U);
    if (cur < 0) ++cnt;
    return cnt <= k;
}
void solve()
{
    cin>>n>>k;
    forn(_, n-1)
    {
        int a, b; cin>>a>>b; --a, --b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    int lf = 0, rg = 222'222;
    while(lf < rg)
    {
        int mid =( lf + rg) / 2;
        if (test(mid)) rg = mid;
        else lf = mid + 1;
    }
    cout << lf << endl;
}
signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    signed T = 1; // cin >> T;
    for(int i=1;i<=T;++i)
    {
        solve();
    }
    return 0;
}