N,M=gets.split.map(&:to_i)
scs=$<.read.split.map(&:to_i).each_slice(2)

# 0.upto(10**N-1) do |i|
[702].each do |i|
    is = i.to_s
    if scs.all? { |s,c| is[s-1] == c.to_s }
        puts is
        exit 0
    end
end

puts -1