function f(a,b)
    if a==1
        return fld(b,100)
    elseif a==2
        return fld(b,10)%10
    else
        return b%10
    end
end
function main()
    n,m=parse.(split(readline()))
    a=[parse.(split(readline())) for i=1:m]
    for i=0:10^(n+1)-1
        flag=true
        for j in a
            if f(j[1],i)!=j[2] || (n!=1&&f(4-n,i)==0)
                flag=false
            end
        end
        if Bool(flag)
            print(i)
            return 0
        end
    end
    print(-1)
end
main()