N, M = gets.split(" ").map(&:to_i)
ans = Array.new(N, "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 || (ans[0] == 0 && N != 1)
    puts -1
else
    if ans[0] == "x"
        ans[0] = 1
    end
    ans.each_with_index do |a, i|
        if a != "x"
           num += a * 10**(N - i - 1)
        end
    end
    puts num
end
