n, m = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(m)]
ans = [10] * n

for i in arr:
    s = i[0] - 1
    c = i[1]
    if ans[s] > c:
        ans[s] = c

for i, num in enumerate(ans):
    if num == 10:
        ans[i] = 0

if ans[0] == 0:
    print(-1)
else:
    print(*ans, sep="")
