N, M = map(int, input().split())

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

ans = [set() for _ in range(N)]

for i in range(M):
    ans[sc[i][0] - 1].add(sc[i][1])


ans_2 = ''
for i in range(N):
    if len(ans[i]) > 1 or ans[0] == 0:
        ans_2 = -1
        break
    else:
        if len(ans[i]) == 0:
            ans_2 += str(0)
        else:
            ans_2 += str(max(ans[i]))

print(ans_2)
