
def goalnum( n, amida )
	p = n
	amida.each_with_index{|e,i|
		if p == e[ 0 ]
			p = e[ 1 ]
		elsif p == e[ 1 ]
			p = e[ 0 ]
		end
#		print "#{i}:#{p}\n"
	}
	return p
end


array = Array.new
width = $stdin.gets.chomp.to_i
n = $stdin.gets.chomp.to_i
n.times{
	line = $stdin.gets.chomp
	yokobow = line.split( /,/ )
	yokobow.map!{ |i| i.to_i }
	array << yokobow
}
array.reverse!
1.upto( width ){ |w|
	puts goalnum( w, array )	
}
