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 len(possibility[i]) == 0:
        possibility[i].append(0)
    possibility[i] = set(possibility[i])
    if i == 0:
        if list(possibility[i])[0] == 0:
            ans = -1
            break
    if len(possibility[i]) != 1:
        ans = -1
        break
    ans += str(list(possibility[i])[0])

print(ans)