import sys

n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
ans = [0] * n
check = [10] * n
for i in l:
    if check[i[0] - 1] == 10:
        ans[i[0] - 1] = i[1]
        check[i[0] - 1] = i[1]
    elif check[i[0] - 1] != i[1]:
        print(-1)
        sys.exit()

    if i[0] == 1 and i[1] == 0 and n != 1:
        print(-1)
        sys.exit()

for i in ans:
    print(i, end="")
