import numpy as np
import math





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


num=np.zeros(n)
num[:] = np.nan

sandc=np.zeros((m,2))

flag=0
for i in range(0,m):
    sandc[i][0], sandc[i][1]= map(int, input().split())

for i in range(0,m):

    if (not math.isnan(num[int(sandc[i][0]-1)])) and num[int(sandc[i][0]-1)]!= sandc[i][1]:
        flag=-1
        break

    if  int(sandc[i][0]==1) and int(sandc[i][1]==0):
        flag=-1
        break
       

    num[int(sandc[i][0]-1)]=sandc[i][1]
    



for i in range(0,n):
     if  math.isnan(num[i]):
         if  i==0 and n>1:
            num[i]=1
         else:
            num[i]=0


pri_num=0
if flag==-1:
    print(flag)
else:
    for i in range(0,n):
   
       pri_num=pri_num+num[i]*10**(n-i-1)


    print(int(pri_num))