n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]

number=[99]*n
if m==0 and n==1:
    print(0)
    exit()
if m==0 and n==2:
    print(10)
    exit()
if m==0 and n==3:
    print(100)
    exit()
flag=True
for x,y in a:
    if number[x-1]!=99:
        if number[x-1]!=y:
            flag=False
    number[x-1]=y
if flag==False:
    print(-1)
    exit()
if number[0]==0:
    print(-1)
    exit()
for i in range(n):
    if number[i]==99:
        number[i]=0
if number[0]==0:
    number[0]=1
for i in number:
    print(i,end="")