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

ans = [None] * N

for i in a:
    if ans[i[0]-1] is None:
        ans[i[0]-1] = i[1]
    elif ans[i[0]-1] != i[1]:
        print(-1)
        exit()

if ans[0] == 0:
    print(-1)
    exit()

for i, v in enumerate(ans):
    if v is None:
        ans[i] = 0

if ans[0] == 0:
    ans[0] = 1

print(''.join(list(map(str,ans))))

