#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;


using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int to[400001], ne[400001], he[200001];
int Q[200001], pl[200001], dl[200001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, K;
	cin >> N >> K;
	int k = 1;
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		to[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	int q = 0, p = 0;
	Q[q++] = 1;
	while (p < N) {
		int u = Q[p++];
		int tmp = 0;
		int ind = he[u];
		he[u] = 0;
		while (ind) {
			int v = to[ind];
			tmp = ne[ind];
			if (he[v] > 0) {
				Q[q++] = v;
				ne[ind] = he[u];
				he[u] = -ind;
			}
			ind = tmp;
		}
	}

	int are = 1000000, pd0 = are;
	int L = 0, R = (N + K - 1) / K;
	while (L + 1 < R) {
		int wj = (L + R) / 2;

		int num = 0;

		for (int i = N - 1; i >= 0; i--) {
			int po = pd0 - 1;
			int dd = pd0;
			int u = Q[i];
			for (int ind = -he[u]; ind; ind = -ne[ind]) {
				int v = to[ind];
				if (po < pl[v]) po = pl[v];
				if (dd < dl[v]) dd = dl[v];
			}
			if (po >= dd) dd = 0;
			if (dd >= pd0 + wj) {
				num++;
				po = pd0 + wj;
				dd = 0;
			}
			pl[u] = po - 1;
			dl[u] = dd + 1;
		}

		int are = num + (dl[1] > pd0);
		if (are > K) L = wj;
		else R = wj;

		pd0 += are;
	}

	co(R);

	Would you please return 0;
}
#include<bits/stdc++.h>
#define il inline
#define re register
#define ll long long
using namespace std;
#define MAXN 200005
namespace hyy
{
	#define DEBUG 1
	#define isdigit(x) (x>='0'&&x<='9')
    const int MAXSIZE=1<<20;
    inline char gc()
	{
		#if DEBUG
        return getchar();
		#endif
        static char buf[MAXSIZE];
		static char *p1=buf+MAXSIZE;
		static char *p2=buf+MAXSIZE;
        if(p1==p2)
		{
        	p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin);
		}
		if(p1==p2)
		{
			return -1;
		}
		return *p1++;
    }
    inline bool blank(char ch)
	{
        return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
    }
    template<class T> inline void read(T &x)
	{
        register double tmp=1;
        register bool sign=0;
        x=0;
        register char ch=gc();
        for(;!isdigit(ch);ch=gc())
		{
        	if(ch=='-')
			{
        		sign=1;
			}
		}
        for(;isdigit(ch);ch=gc())
		{
        	x=(x<<1)+(x<<3)+(ch^48);
		}
        if(ch=='.')
		{
        	for(ch=gc();isdigit(ch);ch=gc())
			{
        		tmp/=10.0;
				x+=tmp*(ch-48);
			}
		}
        if(sign)
		{
        	x=-x;
		}
    }
    inline void read(char *s)
	{
        register char ch=gc();
        for(;blank(ch);ch=gc());
	    for(;!blank(ch);ch=gc())
		{
    		*s++=ch;
		}
        *s=0;
    }
    inline void read(char &c)
	{
        for(c=gc();blank(c);c=gc());
    }
    inline void push(const char &c)
	{
        char pbuf[MAXSIZE];
		char *pp=pbuf;
        if (pp-pbuf==MAXSIZE)
		{
        	fwrite(pbuf,1,MAXSIZE,stdout);
			pp = pbuf;
		}
        *pp++=c;
    }
    template<class T> inline void write(T x)
	{
        static T sta[35];
        T top=0;
        do
		{
            sta[top++]=x % 10;
			x/=10;
        }
		while(x);
		#if DEBUG
        while(top)
		{
        	putchar(sta[--top]+'0');
		}
        return;
		#endif
        while(top)
		{
        	push(sta[--top]+'0');
		}
    }
    template<class T> inline void write(T x,char lastChar)
	{
        write(x);
		putchar(lastChar);
    }
}
using namespace hyy;
using namespace std;
#define in(num) read(num)
#define out(num) write(num) 
//#define mod 998244353
//int n,m;
//ll f[2][MAXN],ans;
//int main(){
//	freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
//	scanf("%d%d",&n,&m);
//	for(re int i=1;i<=m;++i)f[1][i]=1;
//	for(re int i=2,now=0;i<=n;now^=1,++i){
//		for(re int j=1;j<=m;++j){
//			f[now][j]=0;
//			for(re int k=1;k*k<=j;++k){
//				if(!(j%k)){
//					f[now][j]+=f[now^1][k];
//					if(k*k!=j)f[now][j]+=f[now^1][j/k];
//					f[now][j]%=mod;
//				}
//			}
//		}
//	}
//	for(re int i=1;i<=m;++i)ans+=f[n&1][i],ans%=mod;
//	printf("%lld",ans);
//}
#define inf 1e8
int n,m,tot,f[MAXN],g[MAXN];
struct Edge{int next,to;}E[MAXN<<1];
int head[MAXN],cnt;
il void Add(int x,int y){
	E[++cnt].next=head[x],E[cnt].to=y,head[x]=cnt;
}
void dfs(int x,int fa,int mid){
	f[x]=-inf,g[x]=inf;
	for(re int i=head[x];i;i=E[i].next){
		int to=E[i].to;
		if(to==fa)continue;
		dfs(to,x,mid);
		f[x]=max(f[x],f[to]+1),g[x]=min(g[x],g[to]+1);
	}
	if(f[x]+g[x]<=mid)f[x]=-inf;
	if(g[x]>mid)f[x]=max(f[x],0);
	if(f[x]==mid)f[x]=-inf,g[x]=0,++tot;
}
il bool check(int x){
	tot=0,dfs(1,-1,x);
	return tot+(f[1]>=0)<=m;
}
int main(){
	scanf("%d%d",&n,&m);
	for(re int i=1,x,y;i<n;++i)scanf("%d%d",&x,&y),Add(x,y),Add(y,x);
	int l=0,r=n,ans=0;
	for(re int mid;l<=r;mid=l+r>>1,check(mid)?r=(ans=mid)-1:l=mid+1);
	printf("%d\n",ans);
}