require 'pp'

n, m = gets.split.map(&:to_i)
s_m = []
c_m = []
m.times do |i|
    s, c = gets.split.map(&:to_i)
    s_m[i] = s
    c_m[i] = c
end 

range = if n == 1
    (0..9)
elsif n == 2
    (10..99)
else
    (100..999)
end

ans = range.find {|x|
    tmp = x
    digits = []
    while tmp > 0
        digits.push(tmp % 10)
        tmp = tmp / 10
    end

    digits.reverse!

    m.times.all? {|i|
        digits[s_m[i] - 1] == c_m[i]
    }
}

if ans
    puts ans
else
    puts -1
end
