# Problem C - Guess The Number



# input

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



# initialization

input_ok = True

num_list = [-1]*N

for i in range(M):

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

    if N>=2 and s==1:

        if c==0:

            input_ok = False

            break



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

        num_list[s-1] = c

    else:

        if not c==num_list[s-1]:

            input_ok = False

            break



# min_search

if input_ok:

    min_num = 1000

    for n in range(1000):

        n_str = str(n)

        is_ok = True

        if len(n_str)==N:

            for i in range(N):

                if not num_list[i]==-1:

                    if not int(n_str[i])==num_list[i]:

                        is_ok = False

            if is_ok:

                min_num = min(min_num, int(n_str))

        else:

            continue

    # output

    print(min_num)

else:

    print((-1))

# Problem C - Guess The Number



# input

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



# initialization

keta = 0

if N==0:

    keta = 1

else:

    keta = N

keta_list = [-1]*keta

input_ok = True

for i in range(M):

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

    if not keta_list[s-1]==-1:

        if not keta_list[s-1]==c:

            input_ok = False

            break

    else:

        keta_list[s-1] = c

if keta>1 and keta_list[0]==0:

    input_ok = False



if input_ok:

    if keta==1:

        if keta_list[0]==-1:

            print((0))

        else:

            print((keta_list[0]))

    else:

        ans = 100000

        for n in range(1000):

            tmp_keta = len(str(n))

            if tmp_keta==keta:

                tmp = ''

                for i in range(len(keta_list)):

                    if i==0 and keta_list[i]==-1:

                        tmp += '1'

                    elif keta_list[i]==-1:

                        tmp += '0'

                    else:

                        tmp += str(keta_list[i])

                tmp = int(tmp)

                ans = min(ans, tmp)

        print(ans)

else:

    print((-1))

# Problem C - Guess The Number
# input
N, M = list(map(int, input().split()))
# initialization
input_ok = True
num_list = [-1] * N
for i in range(M):
    s, c = list(map(int, input().split()))
    if N >= 2 and s == 1:
        if c == 0:
            input_ok = False
            break
    if num_list[s - 1] == -1:
        num_list[s - 1] = c
    else:
        if not c == num_list[s - 1]:
            input_ok = False
            break
# min_search
if input_ok:
    min_num = 1000
    for n in range(1000):
        n_str = str(n)
        is_ok = True
        if len(n_str) == N:
            for i in range(N):
                if not num_list[i] == -1:
                    if not int(n_str[i]) == num_list[i]:
                        is_ok = False
            if is_ok:
                min_num = min(min_num, int(n_str))
        else:
            continue
    # output
    print(min_num)
else:
    print((-1))

# Problem C - Guess The Number
# input
N, M = list(map(int, input().split()))
# initialization
keta = 0
if N == 0:
    keta = 1
else:
    keta = N
keta_list = [-1] * keta
input_ok = True
for i in range(M):
    s, c = list(map(int, input().split()))
    if not keta_list[s - 1] == -1:
        if not keta_list[s - 1] == c:
            input_ok = False
            break
    else:
        keta_list[s - 1] = c
if keta > 1 and keta_list[0] == 0:
    input_ok = False
if input_ok:
    if keta == 1:
        if keta_list[0] == -1:
            print((0))
        else:
            print((keta_list[0]))
    else:
        ans = 100000
        for n in range(1000):
            tmp_keta = len(str(n))
            if tmp_keta == keta:
                tmp = ""
                for i in range(len(keta_list)):
                    if i == 0 and keta_list[i] == -1:
                        tmp += "1"
                    elif keta_list[i] == -1:
                        tmp += "0"
                    else:
                        tmp += str(keta_list[i])
                tmp = int(tmp)
                ans = min(ans, tmp)
        print(ans)
else:
    print((-1))

+keta = 0 +if N == 0: +    keta = 1 +else: +    keta = N +keta_list = [-1] * keta -num_list = [-1] * N -    if N >= 2 and s == 1: -        if c == 0: +    if not keta_list[s - 1] == -1: +        if not keta_list[s - 1] == c: -    if num_list[s - 1] == -1: -        num_list[s - 1] = c -        if not c == num_list[s - 1]: -            input_ok = False -            break -# min_search +        keta_list[s - 1] = c +if keta > 1 and keta_list[0] == 0: +    input_ok = False -    min_num = 1000 -    for n in range(1000): -        n_str = str(n) -        is_ok = True -        if len(n_str) == N: -            for i in range(N): -                if not num_list[i] == -1: -                    if not int(n_str[i]) == num_list[i]: -                        is_ok = False -            if is_ok: -                min_num = min(min_num, int(n_str)) +    if keta == 1: +        if keta_list[0] == -1: +            print((0)) -            continue -    # output -    print(min_num) +            print((keta_list[0])) +    else: +        ans = 100000 +        for n in range(1000): +            tmp_keta = len(str(n)) +            if tmp_keta == keta: +                tmp = "" +                for i in range(len(keta_list)): +                    if i == 0 and keta_list[i] == -1: +                        tmp += "1" +                    elif keta_list[i] == -1: +                        tmp += "0" +                    else: +                        tmp += str(keta_list[i]) +                tmp = int(tmp) +                ans = min(ans, tmp) +        print(ans)