N, M = list(map(int, input().split()))
ans = [0] * N
invalid = 0
keta_history = {}
for i in range(M):
    keta, atai = list(map(int, input().split()))
    ans[keta - 1] = atai
    if keta in keta_history:
        if keta_history[keta] != atai:
            invalid += 1
    else:
        keta_history[keta] = atai

ans = int(''.join(map(str, ans)))
dummy = [1] + [0] * (N - 1)
if ans < int(''.join(map(str, dummy))):
    invalid += 1

if invalid > 0:
    print(-1)
else:
    print(ans)