n,m= map(int,input().split())
check=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if(check[s]!=-1 and check[s]!=c):
        print(-1)
        exit()
    check[s]=c
#print(check)
if(check[0]==0):
    if(n==1):
      print(0)
    else:
      print(-1)
    exit()
elif(check[0]==-1):
    check[0]=1
    if(n==0):
      check[0]=0
    

for i in range(n):
    if(check[i]==-1):
        check[i]=0
    print(check[i],end="")

    
