n, m = gets.chomp.split.map(&:to_i)

ary = Array.new(n, 10)
max = 0

m.times{|i|
    s, c = gets.chomp.split.map(&:to_i)

    if ary[s-1] > c
        ary[s-1] = c
    end

    if max < s
        max = s
    end
}

newary = ary[0..max-1]
newary.map!{|x| x == 10 ? 0 : x}

result = newary.join.to_i

if n == result.to_s.length
    puts result
else
    puts -1
end