n,m = map(int,input().split())
flag = 0
ans = ['a','a','a']
for _ in range(m):
    s, c = map(int,input().split())
    if ans[s-1]=='a' or ans[s-1]==c:
        ans[s-1]=c
    else:
        flag = 1
        
if flag:
    print(-1)
elif n == 3:
    if ans[0]==0:print(-1)
    else:
        if ans[0]=='a':ans[0]=1
        if ans[1]=='a':ans[1]=0
        if ans[2]=='a':ans[2]=0
        print(100*ans[0] + 10*ans[1] + ans[2])
    
elif m ==2:
    if ans[1]==0:print(-1)
    else:
        if ans[1]=='a':ans[1]=1
        if ans[2]=='a':ans[2]=0
        print(10*ans[1] + ans[2])
    
    
else:
    if ans[2]=='a':print(0)
    else:
        print(ans[2])