n, m = map(int, input().split())

conds = []

for i in range(m):
    s, c = map(int, input().split())
    conds.append([s, c])

# seiri conditions
conds = sorted(conds)
for i in range(len(conds)):
    if i + 1 < len(conds) and (
        conds[i][0] == conds[i + 1][0] and conds[i][1] != conds[i + 1][1]
    ):
        print(-1)
        exit(0)

# list to check conditions.If -1, no condition
fix = [-1] * n

for i in range(len(conds)):
    fix[conds[i][0] - 1] = conds[i][1]

ans = 0
isTopNumFixd = False
for i in range(n):
    if fix[i] == -1:
        fix[i] = 1
        isTopNumFixd = True
    elif fix[i] == 0 and isTopNumFixd is False:
        print(-1)
        exit(0)
for i in range(n):
    ans = ans * 10 + fix[i]

print(ans)

