import sys
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

if N == 1 and sc[0][1] == 0:
    print(0)
    sys.exit()

A = [-1] * N
A[0] = 1
for i in range(M):
    if sc[i][0] == 1 and sc[i][1] == 0:
        print('-1')
        sys.exit()
    if sc[i][0] != 1 and A[sc[i][0] - 1] != -1 and A[sc[i][0] - 1] != sc[i][1]:
        print('-1')
        sys.exit()
    A[sc[i][0] - 1] = sc[i][1]
for a in A:
    if a == -1:
        a = 0
    print(a, end='')
print('')