#include<bits/stdc++.h>
#define int long long 
using namespace std;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

const int N=200005;

int n,k;
vector<int> e[N];

int vis[N],q[N],hi=1,ti,mid,up[N][20];

int get_k(int u) {
	for(int i=0;i<=19;i++) if(mid&(1<<i)) u=up[u][i];
	return u;
}

void dfs(int u,int x) {
//	if(u==12) cout<<x<<endl;
//	cout<<u<<' '<<x<<endl;
	if(x==mid+1 || (vis[u]<=x+1 && vis[u]!=0)) return;
	vis[u]=x+1; 
	for(int i=0;i<e[u].size();i++) {
		dfs(e[u][i],x+1);
	}
}



void get_fa(int u,int fa) {
	up[u][0]=fa;
	for(int i=1;i<=19;i++) up[u][i]=up[up[u][i-1]][i-1];
	for(int i=0;i<e[u].size();i++) {
		if(e[u][i]!=fa) get_fa(e[u][i],u);
	}
}

bool check() {
	int ans=0;
	memset(vis,0,sizeof(vis));
	for(int i=n;i>=1;i--) {
		if(vis[q[i]]) continue;
		ans++;
//		cout<<"g"<<get_k(q[i])<<endl;
//		cout<<vis[]

		dfs(get_k(q[i]),0);
//		for(int j=1;j<=n;j++) cout<<vis[]
//		exit(0);
	}
	if(ans<=k) return 1;
	else return 0;
}


signed main() {
	n=read(),k=read();
	for(int i=1,u,v;i<n;i++) {
		u=read(),v=read();
		e[u].push_back(v),e[v].push_back(u);
	}		
	//求出每个点的距离 
	get_fa(1,1);
	q[++ti]=1; vis[1]=1;
	while(hi<=ti) {
		int u=q[hi++]; 
		for(int i=0;i<e[u].size();i++) {
			if(!vis[e[u][i]]) q[++ti]=e[u][i],vis[e[u][i]]=1;
		}
	}
//	mid=1;
//	cout<<check()<<endl;
	int l=0,r=2e5;
	while(l<r) {
		mid=(l+r)>>1;
		if(check()) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	
	
}

























#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
//mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,T y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,T y){if(x>y)x=y;}
inline int read(){
  #define nc getchar()
  int x=0;char c=nc;bool f=0;
  while(c<48)f|=c=='-',c=nc;
  while(c>47)x=x*10+(c^48),c=nc;
  return f?-x:x;
  #undef nc
}

typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;
const int maxn=2e5+10;
int n,k;vi E[maxn];

int mid;
int res,F[maxn],G[maxn];

void dfs(int u,int f){
  F[u]=1e9,G[u]=-1;
  for(int v:E[u])if(v!=f){
    dfs(v,u);
    chkmin(F[u],F[v]+1);
  }
  for(int v:E[u])if(v!=f){
    if(G[v]+F[u]>=mid){
      chkmax(G[u],G[v]+1);
    }
  }
  if(F[u]>mid)chkmax(G[u],0);
  if(G[u]==mid){
    res++,F[u]=0,G[u]=-1;
  }
}

void solve(){
  cin>>n>>k;
  rep(i,2,n){
    int u=read(),v=read();E[u].push_back(v),E[v].push_back(u);
  }
  int l=1,r=n;
  while(l<r){
    mid=(l+r)/2,res=0,dfs(1,0);
    if(G[1]!=-1)res++;
    res<=k?r=mid:l=mid+1;
  }
  cout<<l<<endl;
}

signed main(){
//  int T=read();
//  while(T--)solve();
  solve();
  return 0;
 }
