N = gets.to_i hashA = {} hashB = {} N.times { a, b = gets.strip.split(" ") hashA[a] = true hashB.delete(a) if hashB.include?(a) hashB[b] = true if not hashA.include?(b) } puts hashB.keys