hashmap = {}
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]

# N, M = 3, 3
# p = [[1,7],[3,2],[1,7]]

for l in P:
    if l[0] in hashmap and hashmap[l[0]]!=l[1]:
        print(-1)
    else:
        hashmap[l[0]]=l[1]
print(hashmap)    

ans = ""
if 1 not in hashmap:
    ans+="1"
else:
    ans+=str(hashmap[1])
    
for i in range(2,N+1):
    if i not in hashmap:
        ans+="0"
    else:
        ans+=str(hashmap[i])

print(int(ans))