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

ans = [-1] * n

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

if ans[0] == 0:
    if n == 1:
        print(0)
    else:
        print(-1)
    exit()
ans[0] = str(max(1, ans[0]))
for i in range(1, n):
    ans[i] = str(max(0, ans[i]))

print(''.join(ans))

