[N,M] = list(map(int,input().split()))
sc = []
for i in range(M):
    sc.append(list(map(int,input().split())))
#print(sc)

hako=[0]*N
for i in range(M):
    hako[sc[i][0] -1] = sc[i][1]   #桁左から〜桁のを〜にかえる


if N==1:
    print(hako[0],sep='')

elif N==2:
    if hako[0] ==0:
        print('-1')
        #result='-1'
    else:
        print(hako[0],hako[1],sep='')

else:
    if hako[0]==0 and hako[1]==0 or hako[0]==0:
        #result=hako
        print('-1')
    else:
        print(hako[0],hako[1],hako[2],sep='')