boal_cup = 'A'
while line = $stdin.gets
	cups = line.chomp.split( /,/ )
	if cups[ 0 ] == boal_cup
		boal_cup = cups[ 1 ]
	elsif cups[ 1 ] == boal_cup
		boal_cup = cups[ 0 ]
	end
	#puts boal_cup
end
puts boal_cup
