a=input().split(" ")
n=int(a[0])
m=int(a[1])
ans=[]
b=[]
c=[]
for i in range(m):
    x=input().split(" ")
    y=[x[0],x[1]]
    b.append(y)
for i in range(10**(n-1),10**(n)):
    num=list(str(i))
    num=num[::-1]
    num.append(0)
    num=num[::-1]
    count=0
    for j in range(m):
        if int(num[int(b[j][0])])!=int(b[j][1]):
            count+=1
            break
    if count==0:
        c.append(i)
        print(i)
        break
if c==[]:
    print("-1")