n,m=map(int,input().split())
ans=[-1]*n
a,b=map(int,input().split())
ans[a-1]=b

for i in range(m-1):
    a,b=map(int,input().split())
    if ans[a-1]!=-1 and ans[a-1]!=b:
        print(-1)
        exit()
    else:
        ans[a-1]=b
       


if n>1 and ans[0]==0:
    print(-1)
elif n==1:
    if ans[0]==-1:
        print(0)
    else:
        print(ans[0])

elif n==2:
    for j in range(2):
        if ans[j]==-1:
            ans[j]=0
    print(10*ans[0]+ans[1])
else:
    for j in range(3):
        if ans[j]==-1:
            ans[j]=0
    
    print(100*ans[0]+10*ans[1]+ans[2])
    
          