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

check_lis = [-1 for _ in range(N)]

for _ in range(M):

    s,c = list(map(int,input().split()))

    if check_lis[s-1] == -1:

        check_lis[s-1] = c

    else:

        if check_lis[s-1] != c:

            print('-1')

            break

    if check_lis[0] == 0 and N != 1:

        print('-1')

        break

else:

    min_range = 10 ** (N-1)

    max_range = 10 * min_range

    if min_range == 1:

        min_range = 0

    for i in range(min_range, max_range):

        for idx, check in enumerate(check_lis):

            if check == -1:

                continue

            if (i // 10 ** (N - idx - 1)) % 10 != check:

                break

        else:

            print(i)

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

if N == 1:

    min_range = 0

    max_range = 10

else:

    min_range = 10 ** (N-1)

    max_range = 10 ** N

digits_lis = ['not defined' for _ in range(N+1)]

for _ in range(M):

    s, c = list(map(int, input().split()))

    if digits_lis[s] == 'not defined':

        digits_lis[s] = c

    else:

        if digits_lis[s] != c:

            print('-1')

            break

    if digits_lis[1] == 0 and N != 1:

        print('-1')

        break

else:

    for i in range(min_range, max_range):

        for idx, check in enumerate(digits_lis):

            if check == 'not defined':

                continue

            if (i // 10 ** (N - idx)) % 10 != check:

                break

        else:

            print(i)

            break

N, M = list(map(int, input().split()))
check_lis = [-1 for _ in range(N)]
for _ in range(M):
    s, c = list(map(int, input().split()))
    if check_lis[s - 1] == -1:
        check_lis[s - 1] = c
    else:
        if check_lis[s - 1] != c:
            print("-1")
            break
    if check_lis[0] == 0 and N != 1:
        print("-1")
        break
else:
    min_range = 10 ** (N - 1)
    max_range = 10 * min_range
    if min_range == 1:
        min_range = 0
    for i in range(min_range, max_range):
        for idx, check in enumerate(check_lis):
            if check == -1:
                continue
            if (i // 10 ** (N - idx - 1)) % 10 != check:
                break
        else:
            print(i)
            break

N, M = list(map(int, input().split()))
if N == 1:
    min_range = 0
    max_range = 10
else:
    min_range = 10 ** (N - 1)
    max_range = 10**N
digits_lis = ["not defined" for _ in range(N + 1)]
for _ in range(M):
    s, c = list(map(int, input().split()))
    if digits_lis[s] == "not defined":
        digits_lis[s] = c
    else:
        if digits_lis[s] != c:
            print("-1")
            break
    if digits_lis[1] == 0 and N != 1:
        print("-1")
        break
else:
    for i in range(min_range, max_range):
        for idx, check in enumerate(digits_lis):
            if check == "not defined":
                continue
            if (i // 10 ** (N - idx)) % 10 != check:
                break
        else:
            print(i)
            break

-check_lis = [-1 for _ in range(N)] +if N == 1: +    min_range = 0 +    max_range = 10 +else: +    min_range = 10 ** (N - 1) +    max_range = 10**N +digits_lis = ["not defined" for _ in range(N + 1)] -    if check_lis[s - 1] == -1: -        check_lis[s - 1] = c +    if digits_lis[s] == "not defined": +        digits_lis[s] = c -        if check_lis[s - 1] != c: +        if digits_lis[s] != c: -    if check_lis[0] == 0 and N != 1: +    if digits_lis[1] == 0 and N != 1: -    min_range = 10 ** (N - 1) -    max_range = 10 * min_range -    if min_range == 1: -        min_range = 0 -        for idx, check in enumerate(check_lis): -            if check == -1: +        for idx, check in enumerate(digits_lis): +            if check == "not defined": -            if (i // 10 ** (N - idx - 1)) % 10 != check: +            if (i // 10 ** (N - idx)) % 10 != check: