n, m = map(int, input().split())
ans = [0] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == 0:
        ans[s-1] = c
    else:
        if not ans[s-1] == c:
            print(-1)
            exit()
tmp = set(ans)
tmp.remove(0)
if n == 1 and m == 0:
    print(0)
elif not tmp:
    print(-1)
else:
    print(*ans, sep='')