N,M = [int(i) for i in input().rstrip().split()]

C = [list(range(1,10))] + [list(range(10)) for i in range(N-1)]

for m in range(M):
    s,c = [int(i) for i in input().rstrip().split()]
    s -= 1
    if c in C[s]:
        C[s] = [c]
    else:
        print(-1)
        exit()

C = [str(min(c)) for c in C]
print("".join(C))
