#include <bits/stdc++.h>
#include"map"
#include"string"
#include"cmath"
#include"cstdio"
#include"iostream"
#include"cstring"
#include"algorithm"
#include"vector"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#ifdef local
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define f(i, l, r) for (int i = l; i <= r; ++i)
#define rf(i, r, l) for (int i = r; i >= l; --i)
#define all(x) (x).begin(), (x).end()
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)

const int inf = 2e9 + 7;
double eps = 1e-6;
const int mod = 998244353;
const int N = 2e5 + 10;
const double pi = acos(-1.0);
ll power(ll a, ll b) { ll res = 1; while (b) { if (b & 1)res = res * a % mod; a = a * a % mod; b >>= 1; }return res; }
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
/*int len, C[N], clen;
int id(int v) { return lower_bound(C + 1, C + len, v) - C; }
void initC() { sort(C + 1, C + clen+1); len = unique(C + 1, C + 1 + clen) - C - 1; }*/

vector<int> g[N];
int now, need;
int mxdep[N], up[N];
void dfs(int u, int f) {
	mxdep[u] = 0; up[u] = -1;
	for (int v : g[u])if (v != f) {
		dfs(v, u); 
		mxdep[u] = max(mxdep[u], mxdep[v] + 1);
		up[u] = max(up[u], up[v] - 1);
	}
	if (up[u]!=-1) {
		if (mxdep[u] <= up[u])mxdep[u] = -inf;
	}
	if (mxdep[u] == now) {
		need++; mxdep[u] = -inf; up[u] = now;
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	int n, k; cin >> n >> k;
	f(i, 1, n - 1) {
		int u, v; cin >> u >> v;
		g[u].push_back(v); g[v].push_back(u);
	}
	int l = 0, r = n;
	while (l < r) {
		now = mid;
		need = 0; dfs(1, 0); if (mxdep[1]>=0)need++;
		if (need <= k)r = mid;
		else l = mid + 1;
	}
	cout << l;
}
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 998244353;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}
ll bin_pow(ll b, ll p){
	ll res = 1;
	for(ll j = 1, pw = b; j <= p; j <<= 1, pw = mul(pw, pw))
		if(p & j)
			res = mul(res, pw);
	return res; 
}
ll inv(ll x){
	return bin_pow(x, Mod - 2);
}

ll a[N];
ll f[N], iv[N];

ll nCr(ll n, ll r){
	return mul(f[n], mul(iv[r], iv[n - r]));
}

ll dp[N];

vector<int> G[N];
int x;
pll DFS(int u, int p, int d){ // cnt, dep;
	pll nw = {0, Inf}, sn;
	int fl = 0;
	for(auto adj : G[u]){
		if(adj == p) continue;
		sn = DFS(adj, u, d + 1);
		if(!fl){
			fl = 1;
			nw = sn;
			continue;
		}
		nw.F += sn.F;
		if(nw.S > d && sn.S > d){
			nw.S = min(nw.S, sn.S);
		} else if(nw.S <= d && sn.S <= d){
			nw.S = max(nw.S, sn.S);
			nw.F --;
		} else {
			ll a, b;
			if(nw.S > d) a = nw.S, b = sn.S;
			else b = nw.S, a = sn.S;
			if(a - d <= d - b){
				nw.F --;
				nw.S = a;
			} else {
				nw.S = b;
			}
		}
	}
	if(fl == 0){
		nw = {1, d - x};
	} else if(abs(nw.S - d) > x){
		nw.F ++, nw.S = d - x;
	}
	// cerr << "!! " << u << " -> " << nw.F << ", " << nw.S << '\n';

	return nw;
}
int n, k;
bool Check(int t){
	x = t;
	pll res = DFS(1, -1, 0);
	return res.F <= k;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int u, v;
	cin >> n >> k;
	for(int i = 1; i < n; i++){
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	// cerr << "----------\n";
	// Check(1);
	// cerr << "----------\n";

	int L = -1, R = n, mid;
	while(L + 1 < R){
		mid = (L + R) >> 1;
		if(Check(mid)) R = mid;
		else L = mid;
	}
	cout << R << '\n';
	return 0;
}
/*
5 1
1 2
2 3
3 4
1 5

*/