n,m=map(int,input().split())

p = [[int(i) for i in input().split()] for _ in range(m)]

p.append([0,10])

p.sort(key=lambda x:(x[0],x[1]))

A=[]

a=0

for i in range(m):
    if p[i+1][0]==1 and p[i+1][1]==0 and n>1:
        print(-1)
        a=1
        break
    if p[i][0]==p[i+1][0] and not(p[i][1]==p[i+1][1]):
        print(-1)  
        a=1
        break
    elif not(p[i][0]==p[i+1][0]):
        B=p[i+1][0]-p[i][0]
        if B>1:
            for j in range(B-1):
                A.append(0)
        A.append(p[i+1][1])
        
if len(A)==n:
    if A[0]==0:
        A[0]=1
else:
    for i in range(n-len(A)):
        A.append(0)
    if A[0]==0:
        A[0]=1
        

S=''

for i in range(len(A)):
    S=S+str(A[i])

if a==0:
    print(int(S))  