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

rl = [-1]*(N+1)

for s, c in sc:
    if rl[s] == -1 or rl[s] == c:
        rl[s] = c
    else:
        print(-1)
        exit()

ans = ""
for nd in range(1, N+1):
    c = rl[nd]
    if c == -1:
        c = 0
    ans += str(c)

print(ans)