import sys
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
rule = {}

for i in range(M):
    s = sc[i][0]
    c = sc[i][1]
    if s == 1 and c == 0:
        print('-1')
        sys.exit()
    elif s in rule:
        if rule[s] != c:
            print('-1')
            sys.exit()
        else:
            rule[s] = c
    else:
        rule[s] = c
        
if 1 not in rule:
    rule[1] = 1
    
for i in range(N):
    if i + 1 not in rule:
        rule[i + 1] = 0

ans = 0
for i in range(N):
    ans += rule[i+1] * (10 ** (N-i-1))
    
print(ans)           