N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(3)]
visited=[0 for i in range(3)]
for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1]+=1
if S[0]==-1:
    S[0]=1
for i in visited:
    if i>1:
        print(-1)
        sys.exit()
for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')