import sys

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

tmp = []
result = ['0'] * n

for sc in sci:
    for tmp in sci:
        if tmp[0] == sc[0] and tmp[1] != sc[1]:
            print(-1)
            sys.exit()

    result[sc[0] - 1] = str(sc[1])

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