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

ans = [-1] * n

exist = True

for i in range(m):

    s, c = map(int, input().split())

    if (n != 1 and (s, c) == (1, 0)) or (ans[s - 1] != -1 and ans[s - 1] != c):

        exist = False

        break

    else:

        ans[s - 1] = c



if exist:

    for i in range(n):

        if n != 1 and i == 0:

            if ans[i] == -1:

                ans[i] = 1

        else:

            if ans[i] == -1:

                ans[i] = 0

    print(*ans, sep='')

else:

    print(-1)

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

conditions = [tuple(map(int, input().split())) for j in range(m)]

exist = False

for i in range(1000):

    if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in conditions):

        ans = i

        exist = True

        break

print((ans if exist else -1))
n, m = map(int, input().split())
ans = [-1] * n
exist = True
for i in range(m):
    s, c = map(int, input().split())
    if (n != 1 and (s, c) == (1, 0)) or (ans[s - 1] != -1 and ans[s - 1] != c):
        exist = False
        break
    else:
        ans[s - 1] = c
if exist:
    for i in range(n):
        if n != 1 and i == 0:
            if ans[i] == -1:
                ans[i] = 1
        else:
            if ans[i] == -1:
                ans[i] = 0
    print(*ans, sep="")
else:
    print(-1)

n, m = list(map(int, input().split()))
conditions = [tuple(map(int, input().split())) for j in range(m)]
exist = False
for i in range(1000):
    if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in conditions):
        ans = i
        exist = True
        break
print((ans if exist else -1))

-n, m = map(int, input().split()) -ans = [-1] * n -exist = True -for i in range(m): -    s, c = map(int, input().split()) -    if (n != 1 and (s, c) == (1, 0)) or (ans[s - 1] != -1 and ans[s - 1] != c): -        exist = False +n, m = list(map(int, input().split())) +conditions = [tuple(map(int, input().split())) for j in range(m)] +exist = False +for i in range(1000): +    if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in conditions): +        ans = i +        exist = True -    else: -        ans[s - 1] = c -if exist: -    for i in range(n): -        if n != 1 and i == 0: -            if ans[i] == -1: -                ans[i] = 1 -        else: -            if ans[i] == -1: -                ans[i] = 0 -    print(*ans, sep="") -else: -    print(-1) +print((ans if exist else -1))