from collections import defaultdict

d = defaultdict(list)



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

for _ in range(M):

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

    d[s].append(c)



val = [-1] * N



# とりあえず桁を確定させる

for k, v in d.items():

    if len(set(v)) > 1:

        print(-1)

        exit()

    val[k - 1] = v[0]



if N == 1:

    ans = max(0, val.pop())

    print(ans)

    exit()

if N >= 2:

    if val[0] == 0:

        print(-1)

        exit()



    if val[0] == -1:

        val[0] = 1

    for i in range(N):

        val[i] = max(0, val[i])



    print(*val, sep="")

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

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



ans = 10000

L = 10 ** (N - 1)

if N == 1:

    L = 0

U = 10**N



for i in range(L, U):

    x = str(i).zfill(N)

    for s, c in sc:

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

            continue

        break

    else:

        ans = min(ans, i)



if ans >= 10000:

    ans = -1



print(ans)
from collections import defaultdict

d = defaultdict(list)
N, M = map(int, input().split())
for _ in range(M):
    s, c = map(int, input().split())
    d[s].append(c)
val = [-1] * N
# とりあえず桁を確定させる
for k, v in d.items():
    if len(set(v)) > 1:
        print(-1)
        exit()
    val[k - 1] = v[0]
if N == 1:
    ans = max(0, val.pop())
    print(ans)
    exit()
if N >= 2:
    if val[0] == 0:
        print(-1)
        exit()
    if val[0] == -1:
        val[0] = 1
    for i in range(N):
        val[i] = max(0, val[i])
    print(*val, sep="")

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 10000
L = 10 ** (N - 1)
if N == 1:
    L = 0
U = 10**N
for i in range(L, U):
    x = str(i).zfill(N)
    for s, c in sc:
        if x[s - 1] == str(c):
            continue
        break
    else:
        ans = min(ans, i)
if ans >= 10000:
    ans = -1
print(ans)

-from collections import defaultdict - -d = defaultdict(list) -N, M = map(int, input().split()) -for _ in range(M): -    s, c = map(int, input().split()) -    d[s].append(c) -val = [-1] * N -# とりあえず桁を確定させる -for k, v in d.items(): -    if len(set(v)) > 1: -        print(-1) -        exit() -    val[k - 1] = v[0] +N, M = list(map(int, input().split())) +sc = [list(map(int, input().split())) for _ in range(M)] +ans = 10000 +L = 10 ** (N - 1) -    ans = max(0, val.pop()) -    print(ans) -    exit() -if N >= 2: -    if val[0] == 0: -        print(-1) -        exit() -    if val[0] == -1: -        val[0] = 1 -    for i in range(N): -        val[i] = max(0, val[i]) -    print(*val, sep="") +    L = 0 +U = 10**N +for i in range(L, U): +    x = str(i).zfill(N) +    for s, c in sc: +        if x[s - 1] == str(c): +            continue +        break +    else: +        ans = min(ans, i) +if ans >= 10000: +    ans = -1 +print(ans)