arr = Array.new
while line = $stdin.gets
arr << line.chomp.split(" ").map(&:to_i)
end
core = arr[1..-1]
fin=1
t=0
ans = 0
while t<=10**arr[0][0] and fin == 1 do
    flag=0
    a=[]
    num = t
    3.times{|k|
        a[k]=(num % 10); num /= 10
    }
    core.each{|item|
        if a[arr[0][0]-item[0]] != item[1]
            flag = 1
        end
    }
    if flag==0 then
        fin = 0
        ans = t
    end
t+=1
end
if fin == 1 then
    puts "-1"
else
    if ans < 10**(arr[0][0]-1) then
        puts "-1"
    else
        puts ans
    end
end