n,m=io.read("*n","*n","*l")

t={}
if m>=1 then
    for i=1,m do
        s,c=io.read("*n","*n","*l")
        c=tostring(c)
        if not t[s] or t[s]==c then
            t[s]=c
        else
            print(-1)
            return
        end
    end
    for i=1,n do
        if not t[i] and i==1 then
            t[i]="1"
        elseif not t[i] then
            t[i]="0"
        end
    end
    x="0"
    for i=1,n do
        x=x..t[i]
    end
    if #x:sub(2,n+1)~=#tostring(tonumber(x)) then
        print(-1)
        return
    elseif #x:sub(2,n+1)==#tostring(tonumber(x)) then
        print(tonumber(x))
        return
    end
else
    if n==1 then
        print(0)
        return
    else
        x="100"
        print(x:sub(1,n))
        return
    end
end