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

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

if N==1:

    for i in range(10):

        flg = 0

        for j in range(M):

            s,c = A[j]

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

                continue

            else:

                flg = 1

                break

        if flg==0:

            print(i)

            break

    if flg==1:

        print((-1))

else:

    for i in range(10**(N-1),10**N):

        flg = 0

        for j in range(M):

            s,c = A[j]

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

                continue

            else:

                flg = 1

                break

        if flg==0:

            print(i)

            break

    if flg==1:

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

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

n = -1

for x in range(1000):

    x = str(x)

    if len(x)!=N:continue

    ind = 0

    for i in range(M):

        s,c = A[i]

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

            ind=1

            break

    if ind==0:

        n = x

        break

print(n)
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(M)]
if N == 1:
    for i in range(10):
        flg = 0
        for j in range(M):
            s, c = A[j]
            if str(i)[s - 1] == str(c):
                continue
            else:
                flg = 1
                break
        if flg == 0:
            print(i)
            break
    if flg == 1:
        print((-1))
else:
    for i in range(10 ** (N - 1), 10**N):
        flg = 0
        for j in range(M):
            s, c = A[j]
            if str(i)[s - 1] == str(c):
                continue
            else:
                flg = 1
                break
        if flg == 0:
            print(i)
            break
    if flg == 1:
        print((-1))

N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(M)]
n = -1
for x in range(1000):
    x = str(x)
    if len(x) != N:
        continue
    ind = 0
    for i in range(M):
        s, c = A[i]
        if x[int(s) - 1] != str(c):
            ind = 1
            break
    if ind == 0:
        n = x
        break
print(n)

-if N == 1: -    for i in range(10): -        flg = 0 -        for j in range(M): -            s, c = A[j] -            if str(i)[s - 1] == str(c): -                continue -            else: -                flg = 1 -                break -        if flg == 0: -            print(i) +n = -1 +for x in range(1000): +    x = str(x) +    if len(x) != N: +        continue +    ind = 0 +    for i in range(M): +        s, c = A[i] +        if x[int(s) - 1] != str(c): +            ind = 1 -    if flg == 1: -        print((-1)) -else: -    for i in range(10 ** (N - 1), 10**N): -        flg = 0 -        for j in range(M): -            s, c = A[j] -            if str(i)[s - 1] == str(c): -                continue -            else: -                flg = 1 -                break -        if flg == 0: -            print(i) -            break -    if flg == 1: -        print((-1)) +    if ind == 0: +        n = x +        break +print(n)