n, m = gets.chop.split.map(&:to_i)
return puts "-1" if (n < 0 || n > 3) || m > 5
i = 0
arr = []
res = 0
nums = {}
while i < m
    s, c = gets.chop.split.map(&:to_i)
    if (c < 0 || c > 9 || s > n) then
        res = -1
        break
    end
    if !nums[s-1] then 
        nums[s-1] = [c]
    else
        nums[s-1] << c
    end
    i += 1
end
zero_ok = false
ii = 0
while ii < n
    arr[ii] = zero_ok ? (nums[ii]&.min || 0) : nums[ii]&.reject{ |ele| ele == 0}.min
    zero_ok = true if zero_ok == false && arr[ii] > 0
    ii += 1
end
res = -1 if arr.include?(nil)
puts res == -1 ? res : arr.join("").to_i
