#include<bits/stdc++.h>
#define int long long 
using namespace std;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

const int N=200005;

int n,k;
vector<int> e[N];

int vis[N],q[N],hi=1,ti,mid,up[N][20];

int get_k(int u) {
	for(int i=0;i<=19;i++) if(mid&(1<<i)) u=up[u][i];
	return u;
}

void dfs(int u,int x) {
//	if(u==12) cout<<x<<endl;
//	cout<<u<<' '<<x<<endl;
	if(x==mid+1 || (vis[u]<=x+1 && vis[u]!=0)) return;
	vis[u]=x+1; 
	for(int i=0;i<e[u].size();i++) {
		dfs(e[u][i],x+1);
	}
}



void get_fa(int u,int fa) {
	up[u][0]=fa;
	for(int i=1;i<=19;i++) up[u][i]=up[up[u][i-1]][i-1];
	for(int i=0;i<e[u].size();i++) {
		if(e[u][i]!=fa) get_fa(e[u][i],u);
	}
}

bool check() {
	int ans=0;
	memset(vis,0,sizeof(vis));
	for(int i=n;i>=1;i--) {
		if(vis[q[i]]) continue;
		ans++;
//		cout<<"g"<<get_k(q[i])<<endl;
//		cout<<vis[]

		dfs(get_k(q[i]),0);
//		for(int j=1;j<=n;j++) cout<<vis[]
//		exit(0);
	}
	if(ans<=k) return 1;
	else return 0;
}


signed main() {
	n=read(),k=read();
	for(int i=1,u,v;i<n;i++) {
		u=read(),v=read();
		e[u].push_back(v),e[v].push_back(u);
	}		
	//求出每个点的距离 
	get_fa(1,1);
	q[++ti]=1; vis[1]=1;
	while(hi<=ti) {
		int u=q[hi++]; 
		for(int i=0;i<e[u].size();i++) {
			if(!vis[e[u][i]]) q[++ti]=e[u][i],vis[e[u][i]]=1;
		}
	}
//	mid=1;
//	cout<<check()<<endl;
	int l=0,r=2e5;
	while(l<r) {
		mid=(l+r)>>1;
		if(check()) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	
	
}

























#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define PB push_back
#define MK make_pair
using namespace std;
#define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl

const int maxn = 2e5 + 5;
const int modu = 998244353; // 1e9 + 7
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

void read(LL &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}

void read(int &x) { LL y; read(y); x = (int)y; }
void read(char &ch) { char s[3]; scanf("%s", s); ch = s[0]; }
void read(char *s) { scanf("%s", s); }
template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }

int n, k, m;
int mind[maxn], f[maxn], maxd[maxn];
vector<int> g[maxn];

int dfs(int x, int fa) {
    mind[x] = inf;
    maxd[x] = 0;
    f[x] = 0;
    for (int y: g[x]) if (fa != y) {
        dfs(y, x);
        maxd[x] = max(maxd[x], maxd[y]+1);
        mind[x] = min(mind[x], mind[y]+1);
        f[x] += f[y];
    }
    if (maxd[x] + mind[x] <= m) {
        maxd[x] = -1;
    }
    if (maxd[x] == m) {
        f[x]++;
        mind[x] = 0;
        maxd[x] = -1;
    }
    return f[x];
}

int cal(int _m) {
    m = _m;
    dfs(1, 0);
    if (maxd[1] >= 0) return f[1]+1;
    else return f[1];
}

int bs(int l, int r) {
    while (l < r) {
        int mid = l+r >> 1;
        if (cal(mid) <= k) r = mid;
        else l = mid+1;
    }
    return l;
}

int main() {
    // freopen("my.txt", "w", stdout);
    read(n, k);
    for (int i = 0; i < n-1; ++i) {
        int u, v;
        read(u, v);
        g[u].PB(v);
        g[v].PB(u);
    }
    printf("%d\n", bs(0, n));
	return 0;
}