import math



N, M = list(map(int, input().split()))



candidate = []

for i in range(1000):

    if N == len(str(i)):

        candidate.append(i)



for _ in range(M):

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

    tmp = []

    for n in candidate:

        if int(str(n)[s - 1]) == c:

            tmp.append(n)

    candidate = tmp



if candidate:

    print((candidate[0]))

else:

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

nums = []

for i in range(1000):

    if len(str(i)) == n:

        nums.append(i)



for _ in range(m):

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

    next_nums = []

    for a in nums:

        if int(str(a)[s - 1]) == c:

            next_nums.append(a)

    nums = next_nums



print((nums[0] if nums else -1))

import math

N, M = list(map(int, input().split()))
candidate = []
for i in range(1000):
    if N == len(str(i)):
        candidate.append(i)
for _ in range(M):
    s, c = list(map(int, input().split()))
    tmp = []
    for n in candidate:
        if int(str(n)[s - 1]) == c:
            tmp.append(n)
    candidate = tmp
if candidate:
    print((candidate[0]))
else:
    print((-1))

n, m = list(map(int, input().split()))
nums = []
for i in range(1000):
    if len(str(i)) == n:
        nums.append(i)
for _ in range(m):
    s, c = list(map(int, input().split()))
    next_nums = []
    for a in nums:
        if int(str(a)[s - 1]) == c:
            next_nums.append(a)
    nums = next_nums
print((nums[0] if nums else -1))

-import math - -N, M = list(map(int, input().split())) -candidate = [] +n, m = list(map(int, input().split())) +nums = [] -    if N == len(str(i)): -        candidate.append(i) -for _ in range(M): +    if len(str(i)) == n: +        nums.append(i) +for _ in range(m): -    tmp = [] -    for n in candidate: -        if int(str(n)[s - 1]) == c: -            tmp.append(n) -    candidate = tmp -if candidate: -    print((candidate[0])) -else: -    print((-1)) +    next_nums = [] +    for a in nums: +        if int(str(a)[s - 1]) == c: +            next_nums.append(a) +    nums = next_nums +print((nums[0] if nums else -1))