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