N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
possibility = [[], [], []]

for i in range(M):
    for j in range(N):
        if sc[i][0]==j+1:
            possibility[j].append(sc[i][1])
ans = ''
for i in range(N):
    if i == 0:
        if 0 in list(set(possibility[i])):
            ans = -1
            break
        elif possibility[i] == []:
            ans += str(1)
            continue
    if len(possibility[i]) == 0:
        ans += str(0)
        continue
    if len(set(possibility[i])) != 1:
        ans = -1
        break
    ans += str(list(set(possibility[i]))[0])

print(ans)