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

A = [[] for i in range(3)]

for i in range(M):
    if data[i][0] == 1 and data[i][1] == 0:
        print(-1)
        exit()
    else:
        A[data[i][0]-1].append(data[i][1])

for i in range(N):
    A[i] = set(A[i])
    if len(A[i]) > 1:
        print(-1)
        exit()

B = []
for i in range(N):
    if len(A[i]) == 1:
        for s in A[i]:
            B.append(s)
    else:
        B.append(0)

ans = str(B[0])
for i in range(1,N):
    ans += str(B[i])

print(ans)