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])

ans=[[] for i in range(N)]
if A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)

elif A[0][0]==1:
    ans[0]=A[0][1]
elif A[0][0]!=1:
    ans[0]=1
    pt=1
    while pt+1<A[0][0]:
        ans[pt]=0
        pt+=1
    ans[pt]=A[0][1]
    pt+=1

for i in range(1,M):
    while pt+1<A[i][0]:
        ans[pt]=0
        pt+=1
    if A[i-1][0]==A[i][0] and A[i-1][1]!=A[i][1]:
        print(-1)
        exit(0)
    else: ans[pt]=A[i][1]
        
print(''.join(map(str,ans))) 