N,M=map(int,input().split())
S=["0" for i in range(N)]
seen=[]
W="good"
for i in range(M):
    A=input().split()
    if A not in seen:
        seen.append(A)
        if S[int(A[0])-1]=="0":
            S[int(A[0])-1]=A[1]
        else:
            W="bad"
ANS="".join(S)
if (ANS[0]=="0" and len(ANS)!=1) or W=="bad":
    print("-1")
else:
    print(ANS)