import sys
rl = sys.stdin.readline

n, m = [int(x) for x in rl().split(' ')]

digits = [-1 for x in range(n)]
for i in range(m):
    s, c = [int(x) for x in rl().split(' ')]
    if digits[s-1] >= 0 and digits[s-1] != c:
        print("-1")
        sys.exit(0)
    else:
        digits[s-1] = c

hasNonZero = False
if digits[0] == 0:
    print("-1")
    sys.exit(0)

for i in range(len(digits)):
    if digits[i] > 0:
        hasNonZero = True
    elif digits[i] < 0:
        if hasNonZero:
            digits[i] = 0
        else:
            digits[i] = 1

ans = 0
for d in digits:
    ans = ans*10 + d
print(ans)
