from collections import defaultdict

n, m = list(map(int, input().split()))

sc = [list(map(int, input().split())) for _ in range(m)]

flag = True

num = {}

for s, c in sc:
    if s == 1 and c == 0:
        flag = False
        break
    elif num.get(s) == None:
        num[s] = c
    else:
        if num.get(s) != c:
            flag = False
            break

a = -1

if flag:
    a = 0
    for k, v in num.items():
        a += v * (10**(n-k))
    if 1 not in num.keys():
        a += 10**(n-1)

print(a)