//#define MULTICASES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
inline void ac();
int main(){
#ifdef MULTICASES
	int t;scanf("%d",&t);while(t--)ac();
#else
	ac();
#endif
	return 0;
}
const int MAXN=200005;
int d,Ans;
vector<int>E[MAXN];
inline int dfs(const int &v=1,const int &f=0){
	int a=-1,b=0,t,u;
	vector<int>::iterator e,ee;
	for(e=E[v].begin(),ee=E[v].end();e!=ee;++e)if((u=*e)!=f){
		t=dfs(u,v);
		if(t<0){if(t<b)b=t;}
		else   {if(t>a)a=t;}
	}
	//ERR("v=%d a=%d b=%d\n",v,a,b);
	//if(a>-b){ERR("I. %d\n",a-1);}
	//else{if(b-1<-d){ERR("II. %d (Ans=%d)\n",d,Ans+1);}else{ERR("III. %d\n",b-1);}}
	if(a>-b)return a-1;
	else{if((--b)<-d){++Ans;return d;}else return b;}
}
inline void ac(){
	int n,k,i,v,u,l,r;
	scanf("%d%d",&n,&k);
	rep(i,2,n){
		scanf("%d%d",&v,&u);
		E[v].push_back(u);
		E[u].push_back(v);
	}
	i=n-1;l=1;r=n-2;
	while(l<=r){
		d=(l+r)>>1;Ans=0;
		if(dfs()<0)++Ans;
		//ERR("\nd=%d Ans=%d\n\n\n\n",d,Ans);
		if(Ans>k)l=d+1;
		else r=(i=d)-1;
	}
	printf("%d\n",i);
}
/*
0. int overflow, array bounds
1. special cases (n=1? n=0?)
2. do smth instead of nothing and stay organized
3. WRITE STUFF DOWN
4. DON'T GET STUCK ON ONE APPROACH
5. STAY CALM AND DON'T GET EXPLODED
*/

#include <iostream>
#include <cstring>

using namespace std;

const int N = 200010, M = 2 * N, INF = 0x3f3f3f3f;

int h[N], e[M], ne[M], idx, n, m, k;
int f[N], g[N], cnt;    //f[u]:u的子孙结点中，最近的特殊点距离u点的距离
                        //g[u]:u的子孙结点中，最远的没被特殊点覆盖的点距离u点的最远的距离
bool st[N];

void add(int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}

void dfs(int u, int father, int mid) {
    f[u] = INF, g[u] = 0;
    for (int i = h[u]; i != -1; i = ne[i]) {
        int j = e[i];
        if (j == father)    continue;
        dfs(j, u, mid);
        f[u] = min(f[j] + 1, f[u]);
        g[u] = max(g[j] + 1, g[u]);
    }
    if (f[u] + g[u] <= mid) g[u] = -INF;
    else if (g[u] == mid) g[u] = -INF, f[u] = 0, cnt ++;
}

int check(int mid) {
    cnt = 0;
    dfs(1, -1, mid);
    if (g[1] >= 0)  cnt ++; //g[1] = 0说明1虽然被覆盖但是它的子节点还有没被覆盖的，且没被覆盖的点距离u的最远距离<mid
    return cnt;
}

int main() {
    memset(h, -1, sizeof h);
    cin >> n >> k;
    for (int i = 1; i < n; i ++)    {
        int a, b;
        cin >> a >> b;
        add(a, b), add(b, a);
    }
    int l = 1, r = n;
    int ans = 1e9;
    while (l < r)  {
        int mid = l + r >> 1;
        if (check(mid) <= k) r = mid;
        else l = mid + 1;
    }
    cout << l;
    return 0;

}
