n, m = gets.chomp.split(" ").map(&:to_i)
ans = -1
num = Array.new(n, nil)
m.times do
    s, c = gets.chomp.split(" ").map(&:to_i)
    next if s == 1 && c == 0
    if num[s-1] == nil
        num[s-1] = c
    else
        num[s-1] = [num[s-1], c].min
    end
end

if num[0] == nil
    puts ans
    exit
end
 
n.times do |i|
    num[i] = 0 if num[i] == nil
end
 
num = num.join("").to_i
 
puts num