n,m = map(int,input().split())
s,c = [0]*m,[0]*m
for i in range(m):
    s[i],c[i] = map(int,input().split())
a = [0]*n

flag = True
                    
for i in range(m):
    if s[i]==1 and c[i]==0:
        flag = False
        
if n==1:
    flag = True

if flag == True:        
    for i in range(m):
        for j in range(i,m):
            if s[i]==s[j]:
                if c[i]!=c[j]:
                    flag = False
                    
if flag == True:
    for i in range(m-1):
        a[s[i]-1] = c[i]
    if n!=1 and a[0]==0:
        a[0]=1
    print(*a,sep="")
else:
    print("-1")