N, M = (int(x) for x in input().split())

A = [list(map(int, input().split())) for i in range(M)]

X = ['0' for i in range(N)]
for i in A:
    X[i[0] - 1] = str(i[1])

F = 1
for i in A:
    if N > 1 and i[0] == 1 and i[1] == 0:
        F = 0
    for j in A:
        if i[0] == j[0] and i[1] != j[1]:
            F = 0
if F == 1:
    print(''.join(X))
else:
    print(-1)