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

sc = sorted(sc)

ans = [-1] * N

for s, c in sc:
    s -= 1
    if ans[s] != -1:
        if ans[s] != c:
            print(-1)
            exit()
    ans[s] = c

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

for i in range(N):
    if ans[i] == -1:
        ans[i] = 0

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