import sys

n, m = map(int, input().split())
sci = [list(map(int, input().split())) for i in range(m)]

tmp = []
results = ['*'] * n

for sc in sci:
    idx = sc[0] - 1
    if results[idx] == '*' \
        or (results[idx] != '*' and results[idx] == str(sc[1])):
        results[sc[0] - 1] = str(sc[1])
    else:
        print(-1)
        sys.exit()

for idx, result in enumerate(results):
    if result == '*':
        if idx == 0:
            results[idx] = '1'
        else:
            results[idx] = '0'

num = int(''.join(results))
if len(str(num)) != n:
    print(-1)
else:
    print(num)