#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int N = 2e5;
int n, k, f[N];
vector<int> G[N];

int dfs(int u, int fa, int mid) {
	f[u] = 0;
	int res = 0;
	vector<int> F;
	for (const int &v : G[u]) {
		if (v == fa) {
			continue;
		}
		res += dfs(v, u, mid);
		if (f[v] == mid) {
			res += 1;
		} else {
			F.push_back(f[v] + 1);
		}
	}
	if (sz(F)) {
		sort(all(F));
		f[u] = F.back();
		rep(i, 1, sz(F)) {
			if (F[i] + F[i - 1] > mid) {
				res += sz(F) - i;
				f[u] = F[i - 1];
				break;
			}
		}
	}
	return res;
}

int check(int mid) {
	int res = dfs(0, -1, mid) + 1;
	// cout << "mid = " << mid << " res = " << res << '\n';
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	rep(i, 0, n - 1) {
		int u, v;
		cin >> u >> v, --u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	} 
	int l = -1, r = n;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (check(mid) <= k) {
			r = mid; 
		} else {
			l = mid; 
		}
	}
	cout << (r + 1) / 2 << '\n';
	return 0;
} 

/*
// My Code in Contest
#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int N = 2e5 + 1;
int n, k, L;
vector<int> G[N];

int *f[N], *g[N], wf[N], wg[N];
int *mf = wf, *mg = wg, tmp[N], mx[N], my[N];
int len[N], s[N], fa[N], tp[N];

void FindSon(int u) {
	for (const int &v : G[u]) {
		if (v == fa[u]) {
			continue;
		}
		fa[v] = u, FindSon(v);
		if (s[u] == -1 or len[v] > len[u]) {
			len[u] = len[v], s[u] = v;
		}
	}
	len[u] += 1;
}

void GetF(int u) {
	if (u == tp[u]) {
		f[u] = mf, mf += len[u];
		g[u] = mg, mg += len[u];
	}
	if (s[u] != -1) {
		f[s[u]] = f[u] + 1;
		tp[s[u]] = tp[u];
		GetF(s[u]);
	}
	for (const int &v : G[u]) {
		if (v == fa[u] or v == s[u]) {
			continue;
		}
		tp[v] = v, GetF(v);
	}
}

void DP(int u) {
	if (s[u] != -1) {
		DP(s[u]);
		f[u][0] = f[u][min(len[s[u]], L + 1)] + 1;
	}
	for (const int &v : G[u]) {
		if (v == fa[u] or v == s[u]) {
			continue;
		}
		DP(v);
		int F = 0;
		rep(i, 0, min(L, len[v]) + 1) {
			f[u][i] += (F += g[u][i]), g[u][i] = 0;
			tmp[i] = min(tmp[i], f[u][i] + my[min(i, L - i)]);
			if (i) {
				tmp[i] = min(tmp[i], f[v][i - 1] + mx[min(i, L - i + 1)]);
			}
			if (i == min(L, len[v])) {
				break;
			}
			mx[i + 1] = min(f[u][i], mx[i]);
			my[i + 1] = min(f[v][i], my[i]);
		} 
		if (min(L, len[v]) + 1 < min(L + 1, len[u])) {
			g[u][min(L, len[v]) + 1] += my[min(L, len[v])];
		}
		rep(i, 0, min(L, len[v]) + 1) {
			tmp[i] = min(tmp[i], f[u][i] + my[min(L, len[v])] + 1);
			f[u][i] = tmp[i], tmp[i] = mx[i] = my[i] = n; 
		}
	}
	if (u == tp[u]) {
		int F = 0;
		rep(i, 0, min(len[u], L + 1)) {
			f[u][i] += (F += g[u][i]), g[u][i] = 0;
		}
	}
	cout << "u = " << u << '\n';
	rep(i, 0, min(L + 1, len[u])) {
		cout << f[u][i] << ' ';
	}
	cout << '\n';
}

int check() {
	DP(0);
	int res = n;
	rep(i, 0, min(len[0], L + 1)) {
		res = min(res, f[0][i]);
	}
	res += 1;
	cout << "L = " << L << " res = " << res << '\n';
	for (int *i = wf; i != mf; *(i++) = 0);
	for (int *i = wg; i != mg; *(i++) = 0);
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	rep(u, 0, n) {
		fa[u] = s[u] = -1;
		tmp[u] = mx[u] = my[u] = n;
	}
	rep(i, 0, n - 1) {
		int u, v;
		cin >> u >> v, --u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	FindSon(0), tp[0] = 0, GetF(0);
	cout << "here" << endl;
	int l = -1, r = n;
	while (r - l > 1) {
		L = (l + r) / 2;
		if (check() <= k) {
			r = L;
		} else {
			l = L;
		}
	}
	cout << (r + 1) / 2 << '\n';
	return 0;
} 
*/
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int n, k;
vector<vector<int>> g;
bool used[200000];
int a[200000], b[200000];
const int INF = 1e9;

void input(){
    cin >> n >> k;
    g.resize(n);
    for(int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
}

void clear(){
    for(int i = 0; i < n; i++){
        a[i] = 0;
        b[i] = INF;
        used[i] = false;
    }
}

void dfs(int v, int &cnt, int c){
    used[v] = true;
    for(int to : g[v]){
        if(!used[to]){
            dfs(to, cnt, c);
            chmax(a[v], a[to]+1);
            chmin(b[v], b[to]+1);
        }
    }
    if(a[v]+b[v] <= c){
        a[v] = -1;
    }
    if(a[v] >= c){
        cnt++;
        a[v] = -1;
        b[v] = 0;
    }
}

bool judge(int c){
    clear();
    int cnt = 0;
    dfs(0, cnt, c);
    if(a[0] != -1) cnt++;
    return cnt <= k;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    if(judge(1)){
        cout << 1 << endl;
        return 0;
    }
    int l = 1, r = n;
    while(r-l > 1){
        int c = (l+r)/2;
        if(judge(c)) r = c;
        else l = c;
    }
    cout << r << endl;
}