n,m=map(int,input().split())
l=[-1]*n
flag=0
for _ in range(m):
    i,el=map(int,input().split())
    if l[i-1]==-1 :
        l[i-1]=el
    elif l[i-1]==el:
        continue
    else:
        flag=1
        break
if(flag==1):
    print(-1)
else:
    
    if l[0]==-1:
        l[0]=1;
    for i in range(1,len(l)):
        if l[i]==-1:
            l[i]=0
    for i in l:
        print(i,end="")