# -*- coding: utf-8 -*-

import sys

import random



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

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



# while True:

#     N = int(random.randint(1,3))

#     M = int()

    

ms = -1

upt = [False]*N

ans = [0]*N

for s,c in sc:

    ms = max(N-s,ms)

    if upt[s-1]:

        if ans[s-1] != c:

            print((-1))

            sys.exit()

        else:

            continue        

    else:

        upt[s-1] = True

        ans[s-1] = c



if upt[0]:

    if ans[0] == 0:

        if N>1:

            print((-1))

            sys.exit()

        else:

            print((0))

            sys.exit()





if M==0 and N==1:

    print((0))

    sys.exit()



A = 0

base = 1

for i,a in enumerate(reversed(ans)):

    if i==N-1 and a == 0:

        A += 1*base

        base *= 10

    else:

        A += a * base

        base *= 10

print(A)

    

# -*- coding: utf-8 -*-

import sys

import random



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

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

#%%

ans = -1

for i in range(1000):

    L = len(str(i))

    if L!=N:

        continue

    a = [0]*L

    tmp = i

    for j in range(L):

        a[L-j-1] = tmp%10

        tmp //= 10

    

    for s,c in sc:

        if a[s-1] != c:

            break

    else:

        if N==1:

            print(i)

        else:

            if a[L-N]!=0:

                print(i)

            else:

                continue

        

        sys.exit()

    continue

print(ans)

    
# -*- coding: utf-8 -*-
import sys
import random

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
# while True:
#     N = int(random.randint(1,3))
#     M = int()
ms = -1
upt = [False] * N
ans = [0] * N
for s, c in sc:
    ms = max(N - s, ms)
    if upt[s - 1]:
        if ans[s - 1] != c:
            print((-1))
            sys.exit()
        else:
            continue
    else:
        upt[s - 1] = True
        ans[s - 1] = c
if upt[0]:
    if ans[0] == 0:
        if N > 1:
            print((-1))
            sys.exit()
        else:
            print((0))
            sys.exit()
if M == 0 and N == 1:
    print((0))
    sys.exit()
A = 0
base = 1
for i, a in enumerate(reversed(ans)):
    if i == N - 1 and a == 0:
        A += 1 * base
        base *= 10
    else:
        A += a * base
        base *= 10
print(A)

# -*- coding: utf-8 -*-
import sys
import random

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
#%%
ans = -1
for i in range(1000):
    L = len(str(i))
    if L != N:
        continue
    a = [0] * L
    tmp = i
    for j in range(L):
        a[L - j - 1] = tmp % 10
        tmp //= 10
    for s, c in sc:
        if a[s - 1] != c:
            break
    else:
        if N == 1:
            print(i)
        else:
            if a[L - N] != 0:
                print(i)
            else:
                continue
        sys.exit()
    continue
print(ans)

-# while True: -#     N = int(random.randint(1,3)) -#     M = int() -ms = -1 -upt = [False] * N -ans = [0] * N -for s, c in sc: -    ms = max(N - s, ms) -    if upt[s - 1]: -        if ans[s - 1] != c: -            print((-1)) -            sys.exit() +#%% +ans = -1 +for i in range(1000): +    L = len(str(i)) +    if L != N: +        continue +    a = [0] * L +    tmp = i +    for j in range(L): +        a[L - j - 1] = tmp % 10 +        tmp //= 10 +    for s, c in sc: +        if a[s - 1] != c: +            break +    else: +        if N == 1: +            print(i) -            continue -    else: -        upt[s - 1] = True -        ans[s - 1] = c -if upt[0]: -    if ans[0] == 0: -        if N > 1: -            print((-1)) -            sys.exit() -        else: -            print((0)) -            sys.exit() -if M == 0 and N == 1: -    print((0)) -    sys.exit() -A = 0 -base = 1 -for i, a in enumerate(reversed(ans)): -    if i == N - 1 and a == 0: -        A += 1 * base -        base *= 10 -    else: -        A += a * base -        base *= 10 -print(A) +            if a[L - N] != 0: +                print(i) +            else: +                continue +        sys.exit() +    continue +print(ans)