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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 2e5+10;
int dp_pego[N], dp_val[N], dp_qnt[N];

vector<int> g[N];
int mdist;

void dfs(int no, int from){
	//prin(no);
	int dist_prox_pego = INT_MAX/2, dist_longe_need = 0;
	dp_qnt[no] = 0;
	for(auto &it : g[no]){
		if(it==from) continue;
		dfs(it,no);
		dp_qnt[no]+=dp_qnt[it];
		if(dp_pego[it]){
			rmin(dist_prox_pego,dp_val[it]+1);
		} else{
			rmax(dist_longe_need,dp_val[it]+1);
		}
	}
	if(dist_prox_pego<=mdist){
		if(dist_prox_pego+dist_longe_need<=mdist){
			dp_pego[no] = 1;
			dp_val[no] = dist_prox_pego;
		} else{
			if(dist_longe_need==mdist){
				dp_qnt[no]++;
				dp_pego[no] = 1;
				dp_val[no] = 0;
			} else{
				dp_pego[no] = 0;
				dp_val[no] = dist_longe_need;
			}
		}
	} else{
		if(dist_longe_need==mdist){
			dp_qnt[no]++;
			dp_pego[no] = 1;
			dp_val[no] = 0;
		} else{
			dp_pego[no] = 0;
			dp_val[no] = dist_longe_need;
		}
	}
	if(no==0 and !dp_pego[no]) dp_qnt[no]++;
}

int need(int _mdist){
	mdist = _mdist;
	dfs(0,-1);
	return dp_qnt[0];
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n, k; cin >> n >> k;
	fr(i,n-1){
		int a, b; cin >> a >> b; a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	int lo = 1, hi = n;
	while(lo<hi){
		int mid = (lo+hi)/2;
		if(need(mid)<=k) hi = mid;
		else lo = mid+1;
	}
	cout << lo << "\n";
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
vector<int>e[N];
int n, k, mid, ret;
int f[N], g[N];
void dfs(int u, int fa) {
    g[u] = 0, f[u] = inf;
    for (int v : e[u]) {
        if (v == fa)continue;
        dfs(v, u);
        f[u] = min(f[u], f[v] + 1);
        g[u] = max(g[u], g[v] + 1);
    }
    if (f[u] + g[u] <= mid) g[u] = -inf;
    else if (g[u] == mid) f[u] = 0, g[u] = -inf, ret++;
}
bool check() {
    ret = 0;
    dfs(1, 0);
    if (g[1] >= 0)ret++;
    return ret <= k;
}
void solve() {
    cin >> n >> k;
    for (int i = 1, u, v; i < n; ++i) {
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int l = 0, r =  n, ans = n;
    while (l <= r) {
        mid = (r + l) >> 1;
        if (check())r = mid - 1, ans = mid;
        else l = mid + 1;
    }
    cout << ans;
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}