// Problem: E - Spread of Information
// Contest: AtCoder - AtCoder Regular Contest 116
// URL: https://atcoder.jp/contests/arc116/tasks/arc116_e
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

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

inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}

const int N=5e5+5;

int n,m,cnt,f[N],g[N],is[N],head[N],ans,gs;

struct nood
{
	int nex,to;
};
nood e[N*2];

inline void jia(int u,int v)
{
	e[++cnt].nex=head[u];
	head[u]=cnt;
	e[cnt].to=v;
}

inline void dfs(int u,int fa,int x)
{
	f[u]=1e9;
	g[u]=-1e9;
	for ( int i=head[u];i;i=e[i].nex )
	{
		int v=e[i].to;
		if(v==fa) continue;
		dfs(v,u,x);
		f[u]=min(f[v]+1,f[u]);
		g[u]=max(g[v]+1,g[u]);
	}
	if(is[u]&&f[u]>x) g[u]=max(g[u],0);
	if(g[u]+f[u]<=x) g[u]=-1e9;
	if(g[u]==x)
		gs++,g[u]=-1e9,f[u]=0;
}

inline bool check(int mid)
{
	gs=0;
	dfs(1,0,mid);
	gs+=(g[1]>=0);
	return gs<=m;
}

int main()
{
	n=read();
	m=read();
	for ( int i=1;i<=n;i++ ) 
		is[i]=1;
	for ( int i=1;i<n;i++ )
	{
		int x,y;
		x=read(),y=read();
		jia(x,y);
		jia(y,x);
	}
	int l=0,r=n;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL unsigned long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>
#define micro 0.000001

using namespace std;

//LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
//LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#else
#define AT
#define AE
#define ce(t)
#define __popcnt64 __builtin_popcountll 
#define __popcnt __builtin_popcount  
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } };

const int max_v = 2e5 + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
const LL mod = 998244353;

vector <int> adj[max_v];
struct node
{
    int cn,sl,mr;        
};

node dfs(int idx,int dist,int par = -1)
{
    if (~par && adj[idx].size() == 1) return { 0,INF,0 };
    node ret = { 0,INF,-INF};

    for (auto& x : adj[idx]) if (x != par)
    {
         node tmp = dfs(x, dist, idx);
         ret.cn += tmp.cn;
         ckmin(ret.sl, tmp.sl+1);
         ckmax(ret.mr, tmp.mr+1);
    }

    //if (ret.mr == -INF) ret.mr = 0;

    if (ret.sl == INF)
    {
        if (ret.mr >= dist)
        {
            ret.sl = 0;
            ret.mr = -INF;
            ++ret.cn;
        }
    }
    else
    {
        if (ret.sl == 2 * dist + 1 || ret.mr>=dist)
        {
            ++ret.cn;
            ret.sl = 0;
            ret.mr = -INF;
        }
        else if (ret.sl > dist)
        {
            ckmax(ret.mr, ret.sl - dist - 1);
        }
        else if(ret.sl+ret.mr <=dist)
        {
            ret.mr = -INF;
        }
    }


    if (par == -1 && ret.mr!=-INF)
    {
        ++ret.cn;
    }
    
    return ret;
}

int main()
{
#ifdef OHSOLUTION
    freopen("input.txt", "r", stdin);
#endif	
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);        
    int n, k; ci(n >> k);

    vector <setl> test;

    fa(i, 0, n - 1)
    {
        int x, y; ci(x >> y); --x, --y;
        adj[x].push_back(y); adj[y].push_back(x);
        if (x > y) swap(x, y);
        test.push_back({ x,y });
    }

    if (n == k)
    {
        co(0);
        return 0;
    }

    int l = 1;
    int r = n;

    while (l != r)
    {
        int mid = l + r >> 1;    
        if (dfs(0,mid).cn <= k) r = mid;
        else l = mid + 1;
    }
    co(l << "\n");

    return 0;
}