#include <bits/stdc++.h>

const int N = 200000;

std::vector<int>G[N + 5];
void adde(int u, int v) {
	G[u].push_back(v), G[v].push_back(u);
}

int n, k, d, t;

int a[N + 5], b[N + 5];
void dfs1(int x, int f) {
	a[x] = b[x] = -1;
	
	int p = -1, q = 0;
	for(auto to : G[x]) if( to != f ) {
		dfs1(to, x);
		p = std::max(p, a[to] - 1);
		q = std::max(q, b[to] + 1);
	}
	if( p >= q ) q = -1;
	if( q == d ) p = d, q = -1, t++;
	
	a[x] = p, b[x] = q;
}

bool check(int _d) {
	d = _d, t = 0, dfs1(1, 0);
	if( b[1] != -1 ) t++;
	return t <= k;
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i=1,u,v;i<n;i++) scanf("%d%d", &u, &v), adde(u, v);
	
	int l = 1, r = n - 1;
	while( l < r ) {
		int m = (l + r) >> 1;
		if( check(m) ) r = m;
		else l = m + 1;
	}
	printf("%d\n", l);
}
#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;
}