f=?0*n=gets.to_i $<.map{|s|s.split.map(&:to_i)}.sort_by{|a,b|-a-b*n}.chunk(&:last).each{|b,r|r.each{|t|f[t[0]]=?1} if f[b]==?0} puts f.reverse.sub(/^0*/,"")