n, m = gets.chomp.split(' ').map(&:to_i)
scs = m.times.map { gets.chomp.split(' ').map(&:to_i) }

digits = {}
scs.each do |s, c|
    d = digits[s]
    if d.nil?
        digits[s] = c
        next
    end

    if d == c
        next
    end

    puts '-1'
    exit
end

if digits[1] == 0
    puts '-1'
    exit
end

if digits.count == 0
    if n == 1
        puts 0
        exit
    end
    puts 10 ** (n - 1)
    exit
end

result = 0
(0...n).each do |i|
    s = i + 1
    d = digits[s] || (s == 1 ? (n == 1 ? 0 : 1) : 0)
    result = result + d * (10 ** (n - s))
end

puts result
