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

L = []

for _ in range(M):

    m = tuple(map(int,input().split()))

    L.append(m)

if N == 1:

    for ans in range(0,10):

        ans = str(ans)

        for x in L:

            if ans[x[0] - 1] != str(x[1]):

                break

        else:

            print(ans)

            exit()

    print((-1))

    exit()

else:

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

        ans = str(ans)

        for x in L:

            if ans[x[0] - 1] != str(x[1]):

                break

        else:

            print(ans)

            exit()

    print((-1))

    exit()



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

L = []

for _ in range(M):

    m = tuple(map(int,input().split()))

    L.append(m)



if(N == 1): lower = 0

else:       lower = 10 ** (N - 1)



for ans in range(lower, 10 ** N ):

    ans = str(ans) 

    for x in L:

        if ans[x[0] - 1] != str(x[1]):

            break

    else: #一度もbreakされてない == 矛盾なし

        print(ans)

        exit()

#ねえよ

print((-1))



N, M = list(map(int, input().split()))
L = []
for _ in range(M):
    m = tuple(map(int, input().split()))
    L.append(m)
if N == 1:
    for ans in range(0, 10):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print((-1))
    exit()
else:
    for ans in range(10 ** (N - 1), 10**N):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print((-1))
    exit()

N, M = list(map(int, input().split()))
L = []
for _ in range(M):
    m = tuple(map(int, input().split()))
    L.append(m)
if N == 1:
    lower = 0
else:
    lower = 10 ** (N - 1)
for ans in range(lower, 10**N):
    ans = str(ans)
    for x in L:
        if ans[x[0] - 1] != str(x[1]):
            break
    else:  # 一度もbreakされてない == 矛盾なし
        print(ans)
        exit()
# ねえよ
print((-1))

-    for ans in range(0, 10): -        ans = str(ans) -        for x in L: -            if ans[x[0] - 1] != str(x[1]): -                break -        else: -            print(ans) -            exit() -    print((-1)) -    exit() +    lower = 0 -    for ans in range(10 ** (N - 1), 10**N): -        ans = str(ans) -        for x in L: -            if ans[x[0] - 1] != str(x[1]): -                break -        else: -            print(ans) -            exit() -    print((-1)) -    exit() +    lower = 10 ** (N - 1) +for ans in range(lower, 10**N): +    ans = str(ans) +    for x in L: +        if ans[x[0] - 1] != str(x[1]): +            break +    else:  # 一度もbreakされてない == 矛盾なし +        print(ans) +        exit() +# ねえよ +print((-1))