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

sc = [list(map(int,input().split())) for _ in range(m)]





for i in range(1000):

    li = []

    j = str(i)

    for k in range(len(j)):

        li.append(int(j[k]))

    if len(li) != n:

        continue

    else:

        flag = True

        for s,c in sc:

            if li[s-1] != c:

                flag = False

        if flag:

            print(j)

            exit()



print((-1))

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

sc = [list(map(int,input().split())) for _ in range(m)]



li = [-1] * n



for s,c in sc:

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

        li[s-1] = c

    else:

        print((-1))

        exit()

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

        print((-1))

        exit()



for i in range(n):

    if li[i] == -1:

        if i == 0 and n != 1:

            li[i] = 1

        else:

            li[i] = 0



ans = ''

for i in li:

    ans += str(i)



print((int(ans)))

n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    li = []
    j = str(i)
    for k in range(len(j)):
        li.append(int(j[k]))
    if len(li) != n:
        continue
    else:
        flag = True
        for s, c in sc:
            if li[s - 1] != c:
                flag = False
        if flag:
            print(j)
            exit()
print((-1))

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

-for i in range(1000): -    li = [] -    j = str(i) -    for k in range(len(j)): -        li.append(int(j[k])) -    if len(li) != n: -        continue +li = [-1] * n +for s, c in sc: +    if li[s - 1] == -1 or li[s - 1] == c: +        li[s - 1] = c -        flag = True -        for s, c in sc: -            if li[s - 1] != c: -                flag = False -        if flag: -            print(j) -            exit() -print((-1)) +        print((-1)) +        exit() +    if n != 1 and s == 1 and c == 0: +        print((-1)) +        exit() +for i in range(n): +    if li[i] == -1: +        if i == 0 and n != 1: +            li[i] = 1 +        else: +            li[i] = 0 +ans = "" +for i in li: +    ans += str(i) +print((int(ans)))