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

digit = [0]*(m)

value = [0]*(m)

for i in range(m):

    digit[i],value[i] = list(map(int,input().split()))



#全探索

ans = 0

for i in range(10**3):

    s = str(i)

    if len(s)!=n: continue

    for j in range(m): 

        if int(s[digit[j]-1]) != value[j]:

            break

    else:

        print(i)

        exit()

print('-1')

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



s, c = [], []



for i in range(m):

    a, b = list(map(int, input().split()))

    s.append(a - 1)

    c.append(b)



for i in range(0, 1000):

    now = str(i)

    if len(now) != n:

        continue

    is_condition = True

    for j in range(m):

        if int(now[s[j]]) != c[j]:

            is_condition = False

    if is_condition:

        print(i)

        exit()



print((-1))
n, m = list(map(int, input().split()))
digit = [0] * (m)
value = [0] * (m)
for i in range(m):
    digit[i], value[i] = list(map(int, input().split()))
# 全探索
ans = 0
for i in range(10**3):
    s = str(i)
    if len(s) != n:
        continue
    for j in range(m):
        if int(s[digit[j] - 1]) != value[j]:
            break
    else:
        print(i)
        exit()
print("-1")

n, m = list(map(int, input().split()))
s, c = [], []
for i in range(m):
    a, b = list(map(int, input().split()))
    s.append(a - 1)
    c.append(b)
for i in range(0, 1000):
    now = str(i)
    if len(now) != n:
        continue
    is_condition = True
    for j in range(m):
        if int(now[s[j]]) != c[j]:
            is_condition = False
    if is_condition:
        print(i)
        exit()
print((-1))

-digit = [0] * (m) -value = [0] * (m) +s, c = [], [] -    digit[i], value[i] = list(map(int, input().split())) -# 全探索 -ans = 0 -for i in range(10**3): -    s = str(i) -    if len(s) != n: +    a, b = list(map(int, input().split())) +    s.append(a - 1) +    c.append(b) +for i in range(0, 1000): +    now = str(i) +    if len(now) != n: +    is_condition = True -        if int(s[digit[j] - 1]) != value[j]: -            break -    else: +        if int(now[s[j]]) != c[j]: +            is_condition = False +    if is_condition: -print("-1") +print((-1))