import sys
n,m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
 
b=[pow(10,n-1)]
count=0
for i in range(0,m):
    
    if A[i][0]==1 and A[i][1]==0 and n>1:
        print(-11)
        sys.exit()
    else:
        b.append(A[i][1]*pow(10,m-A[i][0]))
        if m-A[i][0]==n-1:
            count+=1

#print(b,count)          
if count>0 or n==1:
    b.remove(pow(10,n-1))

if n>1:
    #print([i for i in b if i != 0])
    b=[i for i in b if i != 0]


#print(b)

b=list(set(b))
 
c=[]
for i in range(len(b)):
    c.append(len(str(b[i])))
    
c=list(set(c))

#print(b,c)
 
if len(b)==len(c) and len(str(sum(b)))==n:
    print(sum(b))
else:
    print(-1)