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

ans = [9283749384736]*n

for i in l:
    if ans[i[0]-1] >= i[1]:
        ans[i[0]-1] = i[1]

for i in range(n):
    if ans[i] == 9283749384736:
        ans[i] = 0

s = int("".join(list(map(str, ans))))

if len(str(s)) == n:
    print(s)
else:
    print(-1)

