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

ans = [-1]*n



for i in range(m):

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

    if s == 1 and c == 0 and n != 1:

        print(-1)

        exit()

    if ans[s-1] == -1 or ans[s-1] == c:

        ans[s-1] = c

    else:

        print(-1)

        exit()



if ans[0] == -1 and n != 1:

    ans[0] = 1



for i in range(n):

    if ans[i] == -1:

        ans[i] = 0



print(*ans, sep="")

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

ans = [-1]*n



if n == 1 and m == 0:

    print(0)

    exit()



for i in range(m):

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



    if s == 1 and c == 0 and n != 1:

        print(-1)

        exit()



    if ans[s-1] == -1 or ans[s-1] == c:

        ans[s-1] = c

    else:

        print(-1)

        exit()



if ans[0] == -1:

    ans[0] = 1



for i in range(n):

    if ans[i] == -1:

        ans[i] = 0



print(*ans, sep="")

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

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

+if n == 1 and m == 0: +    print(0) +    exit() -if ans[0] == -1 and n != 1: +if ans[0] == -1: