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

if [1, 0] in l_sc:
    if n==1 and l_sc==[[1, 0]]*m:
        print(0)
    else:
        print(-1)
    exit()

memo = [-1] * n

for i in range(m):
    if memo[l_sc[i][0]-1] != -1:
        if memo[l_sc[i][0]-1] != l_sc[i][1]:
            print(-1)
            exit()
    memo[l_sc[i][0]-1] = l_sc[i][1]

for i in range(n):
    if memo[i] == -1:
        if i == 0:
            memo[0] = 1
        else:
            memo[i] = 0

memo = list(map(str, memo))

print(int("".join(memo)))