import sys
from collections import defaultdict

n, m = map(int, input().split())
tmp = [0] * n
memo = defaultdict(int)

for i in range(m):
    s, c = map(int, input().split())
    if i==0:
        memo[s] = c
    elif s in memo & memo[s]!=c:
        print(-1)
        sys.exit()
    elif (n==3 & s==1 & c==0):
        print(-1)
        sys.exit()
    else:
        tmp[s-1] = c
    
print(0) if sum(tmp) == 0 else print(*tmp, sep="")