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