N, M = map(int, input().split())
l = []
for i in range(N):
    l.append(10)

f = True
for _ in range(M):
    a, b = map(int, input().split())
    a-=1
    if l[a]==b:
        continue
    elif l[a]==10:
        l[a]=b
    else:
        print(-1)
        exit()

if M==0:
    print(0) if N==1 else print(10**(N-1))
elif l[0]==0:
    print(0) if M==1 else print (-1)
else:
    for i in range(N):
        if l[i]==10:l[i]=0
        print(str(l[i]),end="")







