n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
# n, m = 3, 3
# a = [[1, 7], [3, 2], [1, 7]]

if m == 0 or n == 0:
    print(-1)
    exit()

ans = [4e6] * n

for i in a:
    if i[0] == 1 and i[1] <= 0:
        continue
    if ans[i[0]-1] >= i[1]:
        ans[i[0]-1] = i[1]

for i in range(m):
    if ans[i] == 4e6:
        ans[i] = 0

ans = str(int("".join(list(map(str, ans)))))
if len(ans) == n:
    print(ans)
else:
    print(-1)
