p = io.read() n = io.read() for i = 1, n do local scan = string.gmatch(io.read(),"%d+") local a = scan() local b = scan() if a == p then p = b elseif b == p then p = a end end print(p)