N, M = map(int, input().split())
A = [0]*N
res = True
for m in range(M):
    s, c = map(int, input().split())
    if A[s-1] != 0:
        if A[s-1] != c:
            res = False
            break
    else:
        A[s-1] = c
A = str(A[0]) + str(A[1]) + str(A[2])
if res:
    print(A)
else:
    print('-1')