N,M=map(int,input().split())
ans=[0 for i in range(N)]
sign=True
for t in range(M):
    s,c=map(int,input().split())
    if ans[s-1]==0 or ans[s-1]==c:
        ans[s-1]=c
    else:
        sign=False
        break
ANS=''
for s in ans:
    ANS+=str(s)
ANS=int(ANS)
if len(str(ANS))==1:
    ANS=int(ANS)-1
print(int(ANS) if sign==True else -1)