import sys
from collections import defaultdict

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

if m==0:
    print(-1)
    sys.exit()

for i in range(m):
    s, c = map(int, input().split())
    tmp[s-1] = c

    if (n>=2) & (s==1) & (c==0):
        print(-1)
        sys.exit()

    if i==0:
        memo[s] = c
    elif (s in memo) & (memo[s]!=c):
        print(-1)
        sys.exit()
    
print(0) if sum(tmp) == 0 else print(*tmp, sep="")