import sys
N,M=list(map(int, input().split()))

s=[list(map(int, input().split())) for _ in range(M)]

a=["a" for _ in range(N+1)]

if len(s)==0 and N==1:
    print(0)
    sys.exit()
    
elif len(s)==0:
    print(10**(N-1))
    sys.exit()

for i in s:
    if i[1]==0 and i[0]==1:
        print(-1)
        sys.exit()
    

    
    if a[i[0]-1]=="a":
        a[i[0]-1]=str(i[1])
    
    elif a[i[0]-1]!="a" and a[i[0]-1]==str(i[1]):
        continue
        
    elif a[i[0]-1]!="a" and a[i[0]-1]!=str(i[1]):
        print(-1)
        sys.exit()

num=[int(i) if i!="a" else 0 for i in a ]
    
        
if N==1:
    print(int(num[2]))
elif N==2:
    ans=10*int(num[1])+int(num[2])
    if ans//10==0:
        ans+=10
    print(ans)
elif N==3:
    ans=100*int(num[0])+10*int(num[1])+int(num[2])
    
    if ans//100==0:
        ans+=100
    print(ans) 
        
        
    