N,M=map(int,input().split())
a=[]
ans=["a"]*N
for _ in range(M):
    a.append(list(map(int,input().split())))
for i in range(M):
    ans[a[i][0]-1]=a[i][1]
for j in range(N):
    if type(ans[j])!=int:
        ans[j]=0
if ans[0]==0 and ans[1]!=0 and ans[2]!=0:
    if N==2:
        print(*ans[1:3],sep="")
    else:
        print(-1)
elif ans[0]==0 and ans[1]==0 and ans[2]!=0:
    if N==1:
        print(*ans[2:3],sep="")
    else:
        print(-1)
else:
    if N==3:
        print(*ans,sep="")
    else:
        print(-1)