N,M=map(int,input().split())

s_list=[-1]*N

ss=""
for i in range(M):
    s,c=map(int,input().split())
    s-=1
    if s==0 and c==0:
        ss="-1"
    if s_list[s]==-1:
        s_list[s]=c
    else:
        if s_list[s] ==c:
            pass
        elif s_list[s]!=c:
            ss="-1"


if ss=="-1":
    pass
else:
    for i,s in enumerate(s_list):
        if s !=-1:
            ss+=str(s)
        else:
            if i==0:
                ss+=str(1) 
            else:
                ss+=str(0)

print(int(ss))
