N,M=map(int,input().split())
S=[]
C=[]
for _ in range(M):
    s,c=map(int,input().split())
    S.append(s-1)
    C.append(c)

num=[0]*N
for i in range(M):
    if S[i]==0:
        print(-1)
        exit(0)
    if num[S[i]]==0 or num[S[i]]==C[i]:
        num[S[i]]=C[i]
    else:
        print(-1)
        exit(0)

if num[0]==0:
    num[0]=1    
print("".join(map(str,num)))

