N, M = gets.split(" ").map(&:to_i)
ans = Array.new(3, "x")
flag = true
num = 0
M.times do |i|
    s, c = gets.split(" ").map(&:to_i)
    if ans[s - 1] == "x" || ans[s - 1] == c
        ans[s - 1] = c
    else
        flag = false
    end
end
 
if flag == false
    puts -1
else
    ans.each_with_index do |a, i|
        if a != "x"
           num += a * 10**(2 - i)
        end
    end
    if num < 10**(N - 1)
      puts -1
    else
      puts num
    end
end
