N,M = map(int,input().split())
A = [-1]*N
ans = 0
for i in range(M):
    s,c = map(int,input().split())
    if A[s-1]!=-1 and A[s-1]!=c:ans=-1
    else:
        A[s-1]=c
if N==1:
    print(max(A[0],0))
    exit()
for i in range(N):
    if i==0 and A[i]==0:ans=-1
    if A[i]==-1:A[i]=0
    if i==0:A[i]=max(A[i],1)
    A[i] = str(A[i])
print(-1 if ans==-1 else "".join(A))