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

int k, n, dep[200010];
char vis[200010];
vector <int> gl[200010];
int check(const int &u, const int &d, int &cnt);

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d%d", &n, &k);
	for (int i = 1; i < n; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		gl[--u].push_back(--v); gl[v].push_back(u);
	}
	int l = 1, r = n - 2, ans = n - 1;
	while (l <= r) {
		const int mid = l + r >> 1;
		memset(vis, 0, n);
		int cnt = 0, ret = check(0, mid, cnt);
		if (ret < 0)
			++cnt;
		if (cnt > k)
			l = mid + 1;
		else
			r = mid - 1, ans = mid;
	}
	printf("%d\n", ans);
	return 0;
}

int check(const int &u, const int &d, int &cnt) {
	vis[u] = 1;
	int maxv = 0, minv = 0;
	for (int i = 0; i < gl[u].size(); ++i) {
		int &v = gl[u][i];
		if (vis[v])
			continue;
		int tmp = 0, ret = check(v, d, tmp);
		maxv = max(maxv, ret), minv = min(minv, ret);
		cnt += tmp;
	}
	if (maxv + minv >= 1)
		return maxv - 1;
	else if (minv == -d) {
		++cnt;
		return d;
	}
	else
		return minv - 1;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int LOG = 22;
vector<int> G[200010];
int parent[25][200010];
int d[200010];
void dfs(int s, int p){
    parent[0][s] = p;
	for(int v:G[s]){
		if(v==p) continue;
		d[v] = d[s] + 1;
		dfs(v,s);
	}
}
 
void init(int sz,int root){
	d[root] = 0; dfs(root,-1);
	for(int k=0;k<LOG;k++){
		for(int i=0;i<sz;i++){
			if(parent[k][i]<0) parent[k + 1][i] = -1;
			else parent[k + 1][i] = parent[k][parent[k][i]];
		}
	}
}
 
int lca(int u, int v){
	if(d[u]>d[v]) swap(u,v);
	for(int k = 0;k<LOG;k++){
		if((d[v] - d[u])&(1<<k)){
			v = parent[k][v];
		}
	}
	if(u==v) return u;
	for(int k = LOG-1;k>=0;k--){
		if(parent[k][u]!=parent[k][v]){
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}

int dist(int u,int v){return d[u] + d[v] - 2*d[lca(u,v)];}
vector<int> used;
//bool dp[200010][210];
void dfs2(int s,int p,int x){
    used[s] = 1;
    if(x==0) return;
    //if(x==0 || dp[s][x]) return;
    //dp[s][x] = true;
    for(int v: G[s]){
        if(v==p) continue;
        dfs2(v,s,x - 1);
    }
}

int main(){
    int i,n,k; cin >> n >> k;
    for(i=0;i<n - 1;i++){
        int a,b; cin >> a >> b; a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    if(k==n){
        cout << 0 << endl;
        return 0;
    }
    init(n,0);
    vector<pair<int,int>> p;
    for(i=0;i<n;i++) p.push_back({d[i],i});
    sort(p.begin(),p.end()); used.resize(n);
    int l = 0,r = n/k;
    while(r - l>1){
        int mid = (l + r)/2,num = 0;
        vector<int> v;
        for(i=0;i<n;i++) v.push_back(p[i].second), used[i] = 0;
        if(mid<=200 && k>100){
            while(v.size()){
                int u = v.back(); v.pop_back();
                if(used[u]) continue;
                for(i=0;i<mid;i++){
                    if(parent[0][u]==-1) break;
                    u = parent[0][u];
                }
                num++;
                dfs2(u,-1,mid);
            }
        }else{
            vector<int> col;
            while(v.size()){
                int u = v.back(); v.pop_back();
                bool f = true;
                for(i=0;i<col.size();i++){
                    if(dist(u,col[i])<=mid) f = false;
                }
                int x = min(mid,d[u]);
                for(i=LOG;i>=0;i--){
                    if((x>>i)&1) u = parent[i][u];
                }
                if(f) col.push_back(u);
                if(col.size()>k) break;
            }
            num = col.size();
        }
        if(num<=k) r = mid;
        else l = mid;
    }
    cout << r << endl;
}