# -*- coding: utf-8 -*-

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

sc = []

for i in range(m):

    sc.append([int(i) for i in input().split()])



if n == 1:

    if  m == 1:

        print((sc[0][1]))

    if m == 0:

        print((0))

    if m >= 2:

        print((-1))

if n == 2:

    count = 0

    for i in range(10, 100):

        tmp1 = i // 10

        tmp2 = i - (tmp1 * 10)

        flag = True

        for j in range(m):

            if sc[j][0] == 1 and sc[j][1] != tmp1:

                flag = False

            if sc[j][0] == 2 and sc[j][1] != tmp2:

                flag = False

        if flag:

            print(i)

            break

        else:

            count += 1

    if count == 90:

        print((-1))

if n == 3:

    count = 0

    for i in range(100, 1000):

        tmp1 = i // 100

        tmp2 = (i - (tmp1 * 100)) // 10

        tmp3 = i - tmp1 * 100 - tmp2 * 10

        flag = True

        for j in range(m):

            if sc[j][0] == 1 and sc[j][1] != tmp1:

                flag = False

            if sc[j][0] == 2 and sc[j][1] != tmp2:

                flag = False

            if sc[j][0] == 3 and sc[j][1] != tmp3:

                flag = False

        if flag:

            print(i)

            break

        else:

            count += 1

    if count == 900:

        print((-1))

# -*- coding: utf-8 -*-

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

sc = []

for i in range(m):

    sc.append([int(i) for i in input().split()])



for i in range(0, 1000):

    i = str(i)

    if len(i) != n:

        continue

    flag = True

    for j in range(m):

        #print(i, i[sc[j][0] - 1], sc[j][1])

        if i[sc[j][0] - 1] != str(sc[j][1]):

            flag = False

    if flag:

        print(i)

        exit()

print((-1))

# -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
sc = []
for i in range(m):
    sc.append([int(i) for i in input().split()])
if n == 1:
    if m == 1:
        print((sc[0][1]))
    if m == 0:
        print((0))
    if m >= 2:
        print((-1))
if n == 2:
    count = 0
    for i in range(10, 100):
        tmp1 = i // 10
        tmp2 = i - (tmp1 * 10)
        flag = True
        for j in range(m):
            if sc[j][0] == 1 and sc[j][1] != tmp1:
                flag = False
            if sc[j][0] == 2 and sc[j][1] != tmp2:
                flag = False
        if flag:
            print(i)
            break
        else:
            count += 1
    if count == 90:
        print((-1))
if n == 3:
    count = 0
    for i in range(100, 1000):
        tmp1 = i // 100
        tmp2 = (i - (tmp1 * 100)) // 10
        tmp3 = i - tmp1 * 100 - tmp2 * 10
        flag = True
        for j in range(m):
            if sc[j][0] == 1 and sc[j][1] != tmp1:
                flag = False
            if sc[j][0] == 2 and sc[j][1] != tmp2:
                flag = False
            if sc[j][0] == 3 and sc[j][1] != tmp3:
                flag = False
        if flag:
            print(i)
            break
        else:
            count += 1
    if count == 900:
        print((-1))

# -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
sc = []
for i in range(m):
    sc.append([int(i) for i in input().split()])
for i in range(0, 1000):
    i = str(i)
    if len(i) != n:
        continue
    flag = True
    for j in range(m):
        # print(i, i[sc[j][0] - 1], sc[j][1])
        if i[sc[j][0] - 1] != str(sc[j][1]):
            flag = False
    if flag:
        print(i)
        exit()
print((-1))

-if n == 1: -    if m == 1: -        print((sc[0][1])) -    if m == 0: -        print((0)) -    if m >= 2: -        print((-1)) -if n == 2: -    count = 0 -    for i in range(10, 100): -        tmp1 = i // 10 -        tmp2 = i - (tmp1 * 10) -        flag = True -        for j in range(m): -            if sc[j][0] == 1 and sc[j][1] != tmp1: -                flag = False -            if sc[j][0] == 2 and sc[j][1] != tmp2: -                flag = False -        if flag: -            print(i) -            break -        else: -            count += 1 -    if count == 90: -        print((-1)) -if n == 3: -    count = 0 -    for i in range(100, 1000): -        tmp1 = i // 100 -        tmp2 = (i - (tmp1 * 100)) // 10 -        tmp3 = i - tmp1 * 100 - tmp2 * 10 -        flag = True -        for j in range(m): -            if sc[j][0] == 1 and sc[j][1] != tmp1: -                flag = False -            if sc[j][0] == 2 and sc[j][1] != tmp2: -                flag = False -            if sc[j][0] == 3 and sc[j][1] != tmp3: -                flag = False -        if flag: -            print(i) -            break -        else: -            count += 1 -    if count == 900: -        print((-1)) +for i in range(0, 1000): +    i = str(i) +    if len(i) != n: +        continue +    flag = True +    for j in range(m): +        # print(i, i[sc[j][0] - 1], sc[j][1]) +        if i[sc[j][0] - 1] != str(sc[j][1]): +            flag = False +    if flag: +        print(i) +        exit() +print((-1))