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

SC = []
for _ in range(M):
    SC.append(tuple(map(int, input().split())))

# process
ans = 0

A = [-1 for _ in range(N)]

for s, c in SC:
    s -= 1
    if s == 0 and c == 0:
        ans = -1
        break
    elif A[s] == -1:
        A[s] = c
    elif A[s] != c:
        ans = -1
        break

if ans != -1:
    if A[0] == -1:
        A[0] = 1
    for i in range(1, N):
        if A[i] == -1:
            A[i] = 0

    A = A[::-1]
    for i in range(N):
        ans += A[i]*(10**i)

# output
print(ans)
