#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define VI vector<int>
#define PB emplace_back
#define PPB pop_back
#define ALL(x) x.begin(),x.end()
#define endl '\n'
using namespace std;

const int N=500005,L=19;

int n,q;
VI g[N];
auto cmp=[&](int x,int y){return dep[x]<dep[y];};
int dep[N],dfn[N],df,st[N][L];
void dfs(int x,int fa)
{
	dep[x]=dep[fa]+1,st[dfn[x]=++df][0]=x;
	for(int y:g[x])if(y!=fa)dfs(y,x);
}
int rmq(int l,int r)
{
	int t=__lg(r-l+1);
	return min(st[l][t],st[r-(1<<t)+1][t],cmp);
}
int lC

int main()
{
	freopen("query.in","r",stdin),freopen("query.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	
	cin>>n>>q;
	for(int i=1,u,v;i<n;i++)cin>>u>>v,g[u].PB(v),g[v].PB(u);
	dfs(1,0);
	for(int i=n;i;i--)
		for(int j=1;i+(1<<j)-1<=n;j++)
			st[i][j]=min(st[i][j-1],st[i+(1<<j-1)][j-1]);
			
	
	return 0;
}
