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=[]

B=0

for i in range(m):    
    if p[i][0]==p[i+1][0] and not(p[i][1]==p[i+1][1]):
        print(-1)  
        B=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])

S=''


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

if len(S)==n:
    print(int(S))
elif B==0:
    print(-1)