N, M = map(int, input().split())
ans = [-1] * N
for _ in range(M):
    i, n = map(int, input().split())
    if ans[i-1] == -1 or ans[i-1] == n:
        ans[i-1] = n
    else:
        print(-1)
        exit()
ans = [n if n != -1 else 0 for n in ans]
if ans[0] == 0 and len(ans > 1):
    ans[0] = 1
print(*ans, sep='')