#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define ll long long
#define reg register
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define HgS 1000000007
#define to(i) ((ed+(i))->_to)
#define nxt(i) ((ed+(i))->_nxt)
#define pr pair<ll,ll>
#define prpr make_pair
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF)
	{if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	return res*lab;
}
il void prt(ll x,char t='\n')
{
	reg char ch[70];reg int tp=0;
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	if(!tp)ch[++tp]=48;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
il ll uabs(ll x){return x>0?x:-x;}
il ll umax(ll x,ll y){return x>y?x:y;}
il ll umin(ll x,ll y){return x<y?x:y;}
ll n,k,ru,rv,h[200005],d[200005],fa[200005],en,res,ans;
bool vis[200005];
struct edge{ll _to,_nxt;}ed[400005];
il ll add_edge(ll u,ll v){nxt(++en)=h[u];to(en)=v;return h[u]=en;}
pr dfs(int cur,ll x)
{
	vis[cur]=1;
	ll mxf=neinf,mnf=inf;pr tmp;
	for(int i=h[cur];i;i=nxt(i))
	{
		if(!vis[to(i)])
			tmp=dfs(to(i),x),
			mxf=umax(mxf,tmp.first+1),mnf=umin(mnf,tmp.second+1);
	}
	if(mnf>x)mxf=umax(mxf,0);
	if(mxf+mnf<=x)mxf=neinf;
	if(mxf==x){mxf=neinf;mnf=0;++res;}
	return prpr(mxf,mnf);
}
il bool chk(ll r)
{
	res=0;memset(vis,0,sizeof(vis));
	return res+(dfs(1,r).first>=0)<=k;
}
int main()
{
	ans=n=rd();k=rd();
	for(int i=1;i<n;++i)ru=rd(),rv=rd(),add_edge(ru,rv),add_edge(rv,ru);
	reg ll l=0,r=n,mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(chk(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	prt(ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int a, b;
    cin >> a >> b;
    REPR(i, b + 1){
        if(b / i > ceil(a / (double)i)){
            println(i);
            return 0;
        }
    }
    return 0;
}