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

t = [None] * n
invalid = False

for _ in range(m):
    s, c = map(int, input().split())
    if t[s-1] is None or t[s-1] == c:
        t[s-1] = c
    else:
        invalid = True

for i in range(n):
    if t[i] is None:
        if i == 0:
            t[i] = 1
        else:
            t[i] = 0

if invalid:
    print(-1)
else:
    if t[0] == 0 and n > 1:
        print(-1)
    else:
        v = 0
        for i in range(n):
            v += t[-1 - i] * 10 ** i
        print(v)
