var c,s,q,w,j,n,k,i:integer; exi:boolean; a,b:array [1..100] of integer; f:text; begin assign(f,'net.dat'); reset(f); while not(eoln(f)) do begin read(f,n); read(f,k); end; i:=1; while not (eof(f)) do begin read(f,a[i]); readln(f,a[i+1]); i:=i+2; end; for i:=1 to 2*k do b[i]:=a[i]; i:=2; c:=3; j:=2; q:=0; w:=0; exi:=false; while (exi=false) AND (c<=2*k) do begin if (c mod 2)=0 then write('') else if a[i]=b[c] then begin q:=a[i+1]; w:=a[i+2]; b[i+1]:=a[c]; b[i+2]:=a[c+1]; b[c]:=q; b[c+1]:=w; for i:=1 to 2*k do a[i]:=b[i]; end; c:=c+2; end; i:=i+2; assign(f,'net.res'); rewrite(f); writeln(f,b[1]); close(f); end.