import sys

N, M = [int(x) for x in input().split()]
S = [0] * M
C = [0] * M
ans = 0
ansb = 0
ansl = [0] * N
flg = 0
for i in range(M):
    Stemp, Ctemp = [int(x) for x in input().split()]
    S[i] = Stemp
    C[i] = Ctemp

if M == 0:
    print(-1)
    sys.exit()

if N == 1:
    for i in range(M):
        if S[i] >= 2:
            print(-1)
            sys.exit()

if N >= 2:
    for i in range(M):
        if S[i] == 1 and C[i] == 0:
            print(-1)
            sys.exit()
        if S[i] == 1:
            flg = 1

if flg == 0:
    ansl[0] == 1

for i in range(N):
    for j in range(M):
        if S[j] == (i + 1):
            ansl[i] = C[j]

ans = int("".join(map(str, ansl)))

for i in range(M - 1):
    if S[i] == S[i + 1]:
        print(-1)
        sys.exit()

print(ans)