N, M = gets.split(" ").map(&:to_i)
ans = Array.new(3, 0)
flag = true
M.times do |i|
    s, c = gets.split(" ").map(&:to_i)
    if ans[s - 1] == 0 || ans[s - 1] == c
        ans[s - 1] = c
    else
        flag = false
    end
end

if flag == false
    puts -1
else
    num =  ans[0] * 100 + ans[1] * 10 + ans[2]
    if num < 10**(N - 1)
      puts -1
    else
      puts num
    end
end
