#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
const int LOG = 18;
const int MN = 200200;
vvi g;
int kv[MN],dist[MN],nod[MN];
void ds(int u, int p, int di) {
	nod[u] = -1;
	dist[u] = MN;
	for(int i=0;i<g[u].size();i++) {
		int v = g[u][i];
		if(v == p) {continue;}
		ds(v,u,di);
		kv[u] += kv[v];
		dist[u] = min(dist[u],dist[v]+1);
		if(nod[v] >= 0) {
			nod[u] = max(nod[u],nod[v]+1);
		}
	}
	if(dist[u]+nod[u] <= di) {
		nod[u] = -1;
	}
	if(dist[u] > di) {nod[u] = max(nod[u],0);}
	if(nod[u] == di) {
		kv[u]++;
		dist[u] = 0;
		nod[u] = -1;
	}
}
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	ll n,k;
	cin >> n >> k;
	g.assign(n,vi());
	for(int i=0;i<n-1;i++) {
		ll a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int st = 1,ed = n;
	int ls = ed;
	while(st <= ed) {
		memset(kv,0,sizeof(kv));
		int m = (st+ed)/2;
		ds(0,0,m);
		int val = kv[0];
		if(nod[0] >= 0) {
			val++;
		}
		/*
		cout << "SOUP " << m << '\n';
		for(int i=0;i<n;i++) {
			cout << kv[i] << " " << dist[i] << " " << nod[i] << '\n';
		}
		*/
		if(val <= k) {
			ls = m;
			ed = m-1;
		} else {
			st = m+1;
		}
	}
	cout << ls << '\n';
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "asd"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, siz, tong, a[N], b[N], d[N], c[N], h[N], P[N][20];
string s[N];
vector<ll> adj[N];
vector<pll> kq;


ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void dfs(ll u, ll p)
{
    for(int i = 1; i <= 18; i ++)P[u][i] = P[P[u][i-1]][i-1];
    for(ll v : adj[u])
    {
        if(v == p)continue;
        h[v] = h[u] + 1;
        P[v][0] = u;
        dfs(v, u);
    }
}
ll par(ll u, ll dist)
{
    if(h[u] < dist)return 1;
    for(int i = 18; i >= 0; i --)
    {
        if((dist >> i) & 1)
        {
            u = P[u][i];
        }
    }
    return u;
}
void bfs(ll u, ll len)
{
    queue<ll> q;
    d[u] = 0;
    q.push(u);
    while(!q.empty())
    {
        ll u = q.front();
        q.pop();
        if(d[u] == len)continue;
        for(ll v : adj[u])
        {
            if(d[v] > d[u] + 1)
            {
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
}

bool check(ll len)
{
    ll cnt = 0;
    fill_n(d, n+2, mod);
    for(pll x : kq)
    {
        if(d[x.se] <= len)continue;
        ll root = par(x.se, len);
        bfs(root, len);
        ++cnt;
        //cout << root <<" "<<x.se<<'\n';
        if(cnt > k)return false;
    }
    return true;
}
void sol()
{
    cin >> n >> k;
    for(int i = 1; i < n; i ++)
    {
        ll x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1, 0);
    for(int i = 1; i <= n; i ++)kq.pb({h[i], i});
    sort(kq.rbegin(), kq.rend());
    ll lf = 0, rt = n, mid;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(check(mid))rt = mid - 1;
        else lf = mid + 1;
    }
    cout << lf;
}
int main()
{
    if(fopen(task".INP", "r"))
    {
       freopen(task".INP", "r", stdin);
       freopen(task".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
1 2
2 3
3 4
4 5


https://codeforces.com/contest/791/problem/E

*/
