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

ans = [-1] * n


for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    if ans[s] != -1 and ans[s] != c:
        print(-1)
        exit()

    else:
        ans[s] = c

if ans[0] == 0 and n >= 2:
    print(-1)
    exit()

elif ans[0] == -1:
    ans[0] = 1

a = ""
for i in ans:
    a += str(i) if i != -1 else "0"
print(a)