program LCA(Tarjan);
type arr=record
u,v,w,next:longint;
end;
const maxn=;
maxm=;
var eg:array[..maxm*] of arr;
last,lasq,ans,fa:array[..maxn] of longint;
flag:array[..maxn] of boolean;
n,i,j,q,x,y:longint;
procedure add(u,v:longint);
begin
inc(j);
eg[j].u:=u;
eg[j].v:=v;
eg[j].next:=last[u];
last[u]:=j;
end;
procedure adt(u,v,w:longint);
begin
inc(j);
eg[j].u:=u;
eg[j].v:=v;
eg[j].w:=w;
eg[j].next:=last[u];
lasq[u]:=j;
end;
function find(x:longint):longint;
begin
if fa[x]=x then exit(x);
fa[x]:=find(fa[x]);
exit(fa[x]);
end;
procedure lca(u:longint);
var v,i:longint;
begin
i:=last[u];
while i<>- do
begin
v:=eg[i].v;
if not flag[v] then
begin
flag[v]:=true;
lca(v); fa[v]:=u;
end;
i:=eg[i].next;
end;
i:=lasq[u];
while i<>- do
begin
v:=eg[i].v;
if flag[v] and (ans[eg[i].w]=-) then
ans[eg[i].w]:=find(v);
i:=eg[i].next;
end;
end;
begin
for i:= to maxn do begin last[i]:=-; lasq[i]:=-; end;
j:=-;
readln(n,q);
for i:= to n- do
begin
readln(x,y);
add(x,y);
add(y,x);
end;
for i:= to q do
begin
readln(x,y);
adt(x,y,i);
adt(y,x,i);
ans[i]:=-;
end;
fillchar(flag,sizeof(flag),false);
for i:= to n do fa[i]:=i;
flag[]:=true;
lca();
for i:= to q do writeln(ans[i]);
end.