require 'tsort'
class Hash
    include TSort
    alias tsort_each_node each_key
    def tsort_each_child(node, &block)
        (self[node] || []).each(&block)
    end
end
n = gets.to_i
g = {}
n.times do
    i, op, j = gets.chomp.split
    if op == 'lock'
        (g[?d + j] ||= []) << ?u + i
    else
        (g[?u + i] ||= []) << ?d + j
    end
end
begin
    g.tsort
    puts 0
rescue
    puts 1
end
