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

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

ans = 0
for i in range(N):
    if A[i] == -2:
        print(-1)
        exit(0)
    elif A[i] == -1:
        ans *= 10
    else:
        ans = ans * 10 + A[i]

print(ans if ans >= 10**(N-1) else -1)
