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]))) or len(set(possibility[i])) > 1:
            ans = -1
            break
        elif len(possibility[i]) == 0:
            ans += str(1)
            continue
        else:
            ans += str(list(set(possibility[i]))[0])
    else:
        if len(possibility[i]) == 0:
            ans += str(0)
            continue
        elif len(set(possibility[i])) > 1:
            ans = -1
            break
        else:
            ans += str(list(set(possibility[i]))[0])

print(ans)