import sys
N, M = [int(x) for x in input().split()]

digits = {x+1: 0 for x in range(N)}
for _ in range(M):
    s, c = [int(x) for x in input().split()]
    if s == 1 and c == 0:
        if N != 1:
            print(-1)
            sys.exit()
    if digits.get(s, -1) not in [c, 0]:
        print(-1)
        sys.exit()
    digits[s] = c

result = 0
n = 0
for i in sorted(digits.keys(), reverse=True):
    result += digits[i] * (10 ** n)
    n += 1
print(result)
