N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

if N!=1 and A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)
i=1
j=len(A)
while i<j:
    if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]:
        A.pop(i)
        j-=1
        continue
    elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]:
        print(-1)
        exit(0)
    i+=1
ans=[None]*N
if A[0][0]==1:
    ans[0]=A[0][1]
elif A[0][0]==2:
    ans[0]=1
elif A[0][0]==3:
    ans[0]=1
    ans[1]=0

for i in range(1,len(A)):
    if A[i-1][0]==1 and A[i][0]==3:
        ans[1]=0
    ans[A[i][0]-1]=A[i][1]

print(''.join(map(str,ans))) 