import sys

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

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

for i in range(N):
    for j in range(M):
        if S[j] == (i + 1):
            ansl[i] = C[j]
ansb = int("".join(map(str, ansl)))

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

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

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