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