n, m = gets.chop.split.map(&:to_i)
return puts "-1" if (n < 0 || n > 3) || m > 5
i = 0
arr = []
res = 0
while i < m
    s, c = gets.chop.split.map(&:to_i)
    if (c < 0 || c > 9) || (arr[s-1] && arr[s-1] != c) then
        res = -1
        break
    end
    arr[s-1] = c
    i += 1
end
if res != -1 then
    for num in 0..n-1 do
        next if arr[num]
        arr[num] = 0
    end
    if (arr.join("").to_i.to_s != arr.join("").to_s) then
        res = -1 
    else
        res = arr.join("")
    end
end
puts res
