N,M=map(x->parse(Int64,x),split(readline()))
s=zeros(Int,M)
c=zeros(Int,M)
for i in 1:M
    s[i],c[i]=map(x->parse(Int64,x),split(readline()))
end
res=-1
for i in 10^(N-1):(10^N-1)
    snum=string(i)
    flag=true
    for j in 1:M
        if snum[s[j]]!=string(c[j])[1]
            flag=false
            break
        end
    end
    if flag 
        res=i
        break
    end
end
print(res)