import sys
N,M=map(int,input().split())
d={}
for i in range(M):
    a,b=map(int,input().split())
    if a==1 and b==0 and N>1:
        print(-1)
        sys.exit()
    if not a in d:
        d[a]=b
    elif d[a]!=b:
        print(-1)
        sys.exit()
A=[0]*N
for i in d:
    A[i-1]=d[i]
A=[str(A[i]) for i in range(len(A))]
A="".join(A)
A=int(A)
print(int(str(A)))