inp=list(map(int,input().split()))
n=inp[0]
m=inp[1]
arr=[-1]*n
flag=0
if(m==0):
    print (-1)
else:
    for z in range(m):
        inp=list(map(int,input().split()))
        x=inp[0]
        y=inp[1]
        if(x==1 and y==0 and n!=1):
            flag=1
        elif(arr[x-1]!=-1 and arr[x-1]!=y):
            flag=1
        elif(arr[x-1]==-1):
            arr[x-1]=y
    if(flag==1):
        print (-1)
    else:
        k=0
        if(arr[k]==-1):
            arr[k]=1
            k+=1
        gun=0
        while(arr[k]==-1):
            k+=1
            if(k==len(arr)):
                gun=1
                print (0)
                break
        if(gun==0):
            for i in range(len(arr)):
                if(arr[i]==-1):
                    print (0,end="")
                else:
                    print (arr[i],end='')
