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())
k=["0"]*n
if m==0 and n==1:
    print(0)
elif m==0 and n!=1:
    print(10**(n-1))
else:
    for i in range(m):
        if k[s[i]-1]=="0":
            k[s[i]-1]=c[i]
        elif k[s[i]-1]==c[i]:
            k[s[i]-1]=c[i]
        else:
            print(-1)
            break

    else:
        t=0
        if k[0]=="0":
            k[0]=1
        for i in range(n):
            t=t+10**(n-1-i)*int(k[i])
        print(t)