import numpy as np

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

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

sm={}

keys=[]
values=[]
for i in range(M):
    tmp=np.array(input().split(" "),dtype=np.int32)
    keys.append(tmp[0])
    values.append(tmp[1])

for k in range(1,4):
    sm[k]=[]

for k,v in zip(keys,values):
    sm[k].append(v)

for k in keys:
    if(len(set(sm[k]))>=2):
        print(-1)
        exit()

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

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

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