N, M = map(int, input().split())
S = [10 for _ in range(N)]
ans = 0

for i in range(M):
    s, c = map(int, input().split())
    if S[s-1] == 10:
        S[s-1] = c
    elif S[s-1] != c:
        ans = -1
        break

if ans == -1:
    pass
elif N == 1 and S[0] == 0:
    ans = 0
elif S[0] == 0:
    ans = -1
else:
    if S[0] == 10:
        S[0] = 1
    for i in range(N):
        if S[i] == 10:
            S[i] = 0
        ans = ans*10 + S[i]

print(ans)