N,M=map(int,input().split())
INF=10**18
A=[INF]*N
ans=0
for _ in range(M):
    s,c=map(int,input().split())
    s-=1
    if A[s]==INF:
        A[s]=c
    else:
        if A[s]!=c:
            print(-1)
            exit()

if A[0]==0:
    print(-1)
    exit()
elif A[0]==INF:
    A[0]=1

for i in range(1,3):
    if A[i]==INF:
        A[i]=0
A=[str(a) for a in A]
print(''.join(A))