n,m=map(int,input().split())
s=[0]*m
c=[0]*m
for i in range(m):
    s[i],c[i]=map(int, input().split())

for num in range(1000):
    if len(str(num))==n:
        #print(num)
        digit=[0,str(num)[0],str(num)[1],str(num)[2]]
        digit[1]=int(digit[1])
        digit[2]=int(digit[2])
        digit[3]=int(digit[3])
        flag=0
        #print(100*int(digit[1])+10*int(digit[2])+int(digit[3]))
        #print(digit)
        for i in range(m):
            if digit[s[i]]==c[i]:
                flag+=1
        if flag==m:
            print(100*digit[1]+10*digit[2]+digit[3])
            exit()
print("-1")
