import numpy as np

NM=np.array(input().split(" "),dtype=np.int32)

N=NM[0]
M=NM[1]

sm={}
for i in range(M):
    tmp=np.array(input().split(" "),dtype=np.int32)
    sm[tmp[0]]=tmp[1]

for i in range(1,N+1):
    try:
        sm[i]=sm[i]
    except:
        sm[i]=0


result=0
if(N==1):
    result=sm[1]
elif(N==2):
    result=int("{}{}".format(sm[1],sm[2]))
else:
    result=int("{}{}{}".format(sm[1],sm[2],sm[3]))

if(len(str(result))==N):
    print(result)
else:
    print(-1)