parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    sc=[parseMap(split(readline())) for i in 1:m]
    ans=-1
    for i in 100:999
        t=string(i)
        flg=true
        for (s,c) in sc
            if parseInt(t[s])!=c
                flg=false
            end
        end
        if flg==true
            ans=i
            break
        end
    end
    println(ans)
end
main()