import sys

n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
sc = [(s - 1, c) for s, c in sc]

ans = [0] * n

for s, c in sc:
    if s == 0 and c == 0:
        print(-1)
        sys.exit()
    elif ans[s] != 0 and ans[s] != c:
        print(-1)
        sys.exit()
    else:
        ans[s] = c

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

ans = [str(x) for x in ans]

print("".join(ans))