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

A = [-1] * N
ckeck = False
for _ in range(M):
    s, c = map(int, input().split())
    if A[s-1] == -1:
        A[s-1] = c
    elif A[s-1] != c:
        ckeck = True

if ckeck or A[0] == 0:
    print(-1)
    exit(0)

ans = A[0] if A[0] != -1 else 1
for i in range(1, N):
    if A[i] == -1:
        ans *= 10
        continue
    ans = ans * 10 + A[i]

print(ans)
