N,M=map(int,input().split())
l=[-1]*N
flag=True
for i in range(M):
    s,c=map(int,input().split())
    if l[s-1]!=-1 and l[s-1]!=c:
        flag=False
        break
    l[s-1]=c
if flag==False:
    print(-1)
else:
    for i in range(N):
        if l[i]==-1:
            l[i]=0
    ans=""
    count=0
    for i in range(N):
        ans+=str(l[i])
    if ans[0]=="0" and N>1:
        print(-1)
    else:
        print(ans)

    
