[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
flag=[0]*N
for i in range(M):
    if flag[sc[i][0] -1]==0 or hako[sc[i][0] -1]==sc[i][1]:
        hako[sc[i][0] -1] = sc[i][1]
        flag[sc[i][0] -1] = 1
    else:
        N=5


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='')

elif N==3:
    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='')

else:
    print('-1')