#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 k, int p) {
	if (k == 0)
		return INF;	
	if (was[v][k])
		return dp[v][k];
	if (sz[v] < k)
		return -INF;			
	was[v][k] = 1;
    dp[v][k] = -INF;    
    int t1 = k;    
    for (int i = 0; i < g[v].size(); ++i) {
        if (g[v][i] == p)
        	continue;
        int l = 0, r = k + 1;
        while (r - l > 1) {
         	int ans = (r + l) / 2;
         	if (get(g[v][i], ans, v) + 1 >= ANS)
         		l = ans;
         	else
         		r = ans;
        }
        t1 -= l; 	
    }
    if (t1 - 1 <= 0) 
    	dp[v][k] = 0;
    for (int it = 1; it <= n; ++it) {
    	int d_for_this = it;
    	int sum = 0;
    	vector<int> t0, t1;
    	for (int i = 0; i < g[v].size(); ++i) {
    		if (g[v][i] == p)
    			continue;
    		int l1 = 0, r1 = k + 1;
    		while (r1 - l1 > 1) {
    			int max_k = (l1 + r1) / 2;
    			if (get(g[v][i], max_k, v) + 1 >= d_for_this)
    				l1 = max_k;
    			else
    				r1 = max_k;
    		}
    		t1.pb(l1);    		
    		l1 = 0, r1 = k + 1;
    		while (r1 - l1 > 1) {
    			int max_k = (l1 + r1) / 2;
    			if (get(g[v][i], max_k, v) + 1 >= d_for_this && get(g[v][i], max_k, v) + 1 + d_for_this >= ANS)
    				l1 = max_k;
    			else
    				r1 = max_k;
    		}    		    		
    		t0.pb(l1);    	 
        	sum += l1;
        }
        int mx = 0, O = v == 1 ? g[v].size() : g[v].size() - 1;
        for (int i = 0; i < O; ++i) 
        	mx = max(mx, sum - t0[i] + t1[i]);
       	if (mx >= k) 
    		dp[v][k] = it;	
    }
    return dp[v][k];
}

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;	    
	    if (get(1, k, -1) != -INF)
	    	l = ANS;
	    else
	    	r = ANS;		
	}
	printf("%d\n", l);
	cerr << (clock() - start) / CLOCKS_PER_SEC << "\n";
	return 0;
}
