#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,i,j,f[200005],s[200005];
vector<int> g[200005];
int l,r,mid,ans;
void dfs(int x,int fa){
	int i,mx=0,mi=0;s[x]=0;
	for(i=0;i<g[x].size();i++){
		if(g[x][i]==fa) continue;
		dfs(g[x][i],x);
		mx=max(mx,f[g[x][i]]);
		mi=min(mi,f[g[x][i]]);
		s[x]+=s[g[x][i]];
	}
	if(mx+mi<0){
		f[x]=mi+1;
	}
	else{
		f[x]=mx+1;
		if(f[x]>mid){
			f[x]=-mid;
			s[x]++;
		}
	}
}
bool check(){
	dfs(1,0);
	return (s[1]+(f[1]>0))<=m;
}
int main(){
	cin>>n>>m;
	if(n==m){
		puts("0");
		return 0;
	}
	rep(i,n-1){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	l=0;r=ans=n;
	while(l<r){
		mid=(l+r+1)/2;
		if(check()){
			r=mid-1;
			ans=mid;
		}
		else l=mid;
	}
	cout<<ans<<endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int cnt;

void dfs(int i,int p,vector<vector<int>>& edges,vector<int>& a,int l) {
    int mn = l,mx = -l-1;
    bool f = false;
    for (int j : edges[i]) if (j != p) {
        dfs(j,i,edges,a,l);
        if (a[j] > 0) mn = min(mn,a[j]-1);
        if (a[j] <= 0) mx = max(mx,a[j]-1);
        if (a[j] == 1) f = true;
    }
    if (f) {
        a[i] = 0;
        cnt++;
    } else if (mx == -l-1 && mn == l) {
        a[i] = l;
    } else if (mx > -l-1 && -mn <= mx) {
        a[i] = mx;
    } else {
        a[i] = mn;
    }
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<vector<int>> edges(n);
    vector<int> a(n);
    for (int i = 0;i < n-1;++i) {
        int u,v;
        scanf("%d%d",&u,&v);
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    int ok = n,ng = 0;
    while (abs(ok-ng) > 1) {
        int mid = (ok+ng)/2;
        cnt = 0;
        dfs(0,-1,edges,a,mid);
        if (a[0] > 0) cnt++;
        (cnt <= k ? ok : ng) = mid;
    }
    cout << ok << newl;
}