#include<iostream>
#include<cstdio>
using namespace std;
struct Edge{
	int to,nxt;
}e[400005];
int n,k,h[200005],num,f[200005],g[200005],cnt;
void add(int u,int v){
	e[++num].to=v;
	e[num].nxt=h[u];
	h[u]=num;
}
void dfs(int u,int fa,int lim){
	int i,v;
	f[u]=1e9;
	g[u]=0;
	for(i=h[u];i;i=e[i].nxt){
		v=e[i].to;
		if(v!=fa){
			dfs(v,u,lim);
			f[u]=min(f[u],f[v]+1);
			g[u]=max(g[u],g[v]+1);
		}
	}
	if(f[u]+g[u]<=lim)
		g[u]=-1e9;
	if(g[u]>=lim)
		++cnt,f[u]=0,g[u]=-1e9;
}
bool judge(int lim){
	cnt=0;
	dfs(1,0,lim);
	return (cnt+(g[1]>=0))<=k;
}
int solve(){
	int l=1,r=n,mid,res;
	while(l<=r){
		mid=(l+r)>>1;
		if(judge(mid))
			r=mid-1,res=mid;
		else
			l=mid+1;
	}
	return res;
}
int main(){
	ios::sync_with_stdio(false);
	int i,u,v;
	cin>>n>>k;
	for(i=1;i<n;i++){
		cin>>u>>v;
		add(u,v);add(v,u);
	}
	cout<<solve()<<endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
P dfs(int u, int p, vector<vector<int>>&G, int t){
	int ac = 0;
	int mu = -1e9, ma = t;
	for(int v: G[u]) if(v != p){
		auto [fs, sd] = dfs(v,u,G,t); fs--;
		ac += sd;
		if(fs < 0) mu = max(mu,fs);
		else ma = min(ma,fs);
	}
	if(mu+ma >= 0) return {mu,ac};
	else if(ma == 0) ac++;
	return {ma, ac};
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n, k; cin >> n >> k;
	vector<vector<int>> G(n);
	rep(i,n-1){
		int u, v; cin >> u >> v; v--; u--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	int l=-1, r=n-1;
	while(l+1<r){
		int mid = (l+r) / 2;
		auto [m, kk] = dfs(0,0,G,mid); if(m > 0) kk++;
		(kk <= k ? r : l) = mid;
	}
	cout << r << "\n";
}