parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end


#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if ok == length(sc) && i[1] != '0'
        return parse(i)
    end
end             
return -1   
end

ans = main()
println(ans)