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
    if keta == 1 and atai == 0:
        invalid += 1

if invalid > 0:
    print(-1)
else:
    print(''.join(map(str, ans)))
