nm = gets.chomp.split
n = nm[0].to_i
m = nm[1].to_i

s = Array.new
c = Array.new
m.times do
    input = gets.chomp.split
    s << input[0].to_i
    c << input[1].to_i
end

number = "0"
(n - 1).times do
    number += "0"
end

record_s = Array.new
record_c = Array.new
m.times do |i|
    if record_s.include?(s[i]) && record_c[record_s.index(s[i])] != c[i]
        number = "0"
        break
    end

    record_s << s[i]
    record_c << c[i]
    number[(s[i] - 1)] = c[i].to_s
end

if number.to_i.to_s.length == n
    puts number.to_i
else
    puts "-1"
end