#include<ctime>
#include<iostream>
#include<cstdio>
//#include<cmath>
//#include<algorithm>
#include<vector> 
#include<cstring>
#include<string>
//#include<queue>
#define mp make_pair
#define scn second
#define frs first
#define pb push_back
#define NAME "defence"
#define fop freopen(NAME ".in", "r", stdin); freopen(NAME ".out", "w", stdout); 
using namespace std;
const long long P=239017, MaxN=2100000, INF=100000000;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;

vector<int> g[10000];
int t[100002][3];
int n;
int dp[1010][1001], ANS;
int sz[1001];
int was[1001][1000];


int get(int v, int h, int p) {	
	if (h > n || h < 0)	
		return 0; 
	if (was[v][h])
		return dp[v][h];
	was[v][h] = 1;
    dp[v][h] = 0;
    if (h == 0) {	
    	int a = 0;
    	for (int i = 0; i < g[v].size(); ++i) {
    		if (g[v][i] == p)
    			continue;
    		a += get(g[v][i], ANS - 1, v);
   		}    		
   		dp[v][h] = a + 1;
   		dp[v][h] = max(dp[v][h], get(v, h + 1, p));
   		return dp[v][h];   	
   	}
   	vector<int> t0, t1;
   	int sum = 0;
    for (int i = 0; i < g[v].size(); ++i) {
   		if (g[v][i] == p)
   			continue;
   		t0.pb(get(g[v][i], h - 1, v)); 	
   		t1.pb(get(g[v][i], max(ANS - h - 1, h - 1), v)); 	   		
    	sum += t1.back();
    }
    dp[v][h] = max(dp[v][h], get(v, h + 1, p));

    int ans = sum;
    for (int i = 0; i < t0.size(); ++i) 
        ans = max(ans, sum - t1[i] + t0[i]);    	                           
    return dp[v][h] = max(ans, max(dp[v][h], get(v, h + 1, p)));    
}

void dfs(int v, int p) {
	sz[v] = 1;
	for (int i = 0; i < g[v].size(); ++i) 
		if (g[v][i] != p)
			dfs(g[v][i], v), sz[v] += sz[g[v][i]];
}
int k;
double start;
int main(){
	start = clock();
	fop;
	int a, b;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n - 1; ++i)
		scanf("%d%d", &a, &b), g[a].pb(b), g[b].pb(a);	
	dfs(1, 0);		
	int l = 0, r = n + 1;
	while (r - l > 1) {
		ANS = (l + r) / 2;
	    for (int i = 0; i < 1000; ++i)
	    	for (int j = 0; j < 1000; ++j)
	    		was[i][j] = 0;	    
	    int mx = 0;
	    for (int i = 0; i <= n; ++i)
	    	mx = max(get(1, i, -1), mx);
	    if (mx >= k)
	    	l = ANS;
	    else
	    	r = ANS;		
	}
	printf("%d", l);
	cerr << (clock() - start) / CLOCKS_PER_SEC << "\n";
	return 0;
}