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)
    if n != 1 && s == 1 && c == 0
        puts ans
        exit
    end
    if num[s-1] == nil
        num[s-1] = c
    elsif num[s-1] != c
        puts ans
        exit
    end
end
 
n.times do |i|
    num[i] = 0 if num[i] == nil
end
 
puts num.join("").to_i