w = gets.to_i
n = gets.to_i
aArray = Array.new(n)
bArray = Array.new(n)
ans = Array.new(w)
n.times { |count|
	aArray[count], bArray[count] = gets.split(',').map(&:to_i)
}

now = 0
w.times { |vbar|
	now = vbar+1
	n.times { |hbar|
		if now == aArray[hbar]
			now = bArray[hbar]
		elsif now == bArray[hbar]
			now = aArray[hbar]
		end
	}
	ans[now-1] = vbar+1
}

ans.count { |i|
	puts i
}