n,m=map(int,input().split())
L=[10]*3
for i in range(m):
    s,c=map(int,input().split())
    if L[s-1]!=10:
        if L[s-1]!=c:
            print(-1)
            exit()
    else:
        L[s-1]=c
if L[0]==10 or L[0]==0:
    print(-1)
    exit()
else:
    for i in range(n-1):
        if L[i+1]==10:
            L[i+1]=0
print(''.join(map(str,L)))