#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define pb push_back
using namespace std;
const int A=5e5+5, K=23;
int n, m, l, r, a[A], st[A][K], u, v, dat[A];
vector<int> e[A];

void Build(int p, int last, int depth){
	a[p] = depth;
	for(int i=0; i<=1; i++){
		if(e[p][i] == last) continue;
		Build(e[p][i], p, depth+1);
	}
	return;
}
inline int lowbit(int x){ return x & -x; }
inline int Query(int l, int r){
	int k = dat[r-l+1];
	int j = r - (1<<k) + 1;
	return min(st[l][k], st[j][k]); 
}

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1; i<n; i++){
		cin>>u>>v;
		e[u].pb(v); e[v].pb(u);
	}
	for(int i=1; i<=n; i++){
		if(lowbit(i) == i) dat[i] = dat[i-1] + 1;
		else dat[i] = dat[i-1]; // log2
	}
	Build(1, 0, 1);
	for(int i=1; i<=n; i++) st[i][0] = a[i];
	for(int k=1; k<K; k++){
		int j = (i+(1<<(j-1))); j = min(j, n);
		st[i][k] = min(st[i][k-1], st[j][k-1]);
	}
	
	return 0;
}
