N,M=[int(i) for i in input().split(" ")]
number=[-1 for i in range(N)]
for i in range(M):
    s,c=[int(i) for i in input().split(" ")]
    if(number[s-1]==-1):
        number[s-1]=c
    elif(number[s-1]!=c):
        print(-1)
        break
else:
    n=0
    for i in range(N):
        if number[i]==-1:
            if i==0:
                number[i]=1
            else:
                number[i]=0
        n=n*10 + number[i]
    if(len(str(n))==N):
        print(n)
    else:
        print("-1")
