n,m = gets.split.map(&:to_i)
s = Hash.new(nil)
t = Hash.new(0)
an = 0
m.times do 
    a,b = gets.split.map(&:to_i)
    if(t[a] != 0 && s[a] != b)
        an = 1
    end
    s[a] =  b
    t[a] += 1
end
if s[1] == 0 && n != 1
    an = 1
end
if s[1] == nil && (s[2] != nil || s[3] != nil)
    s[1] = 1
end 

if n > 1 && s[2] == nil
    s[2] = 0
end
if n > 1 && s[3] == nil
    s[3] == 0
end

if(n == 1 && an != 1)
    puts s[1]
end

if(n > 1 && an != 1)
    (1..n).each do |i|
        print s[i]
    end
puts
end
if an == 1
    puts -1
end

