N, M = list(map(int, input().split(' ')))
sc = [list(map(int, input().split(' '))) for i in range(M)]


ans_l = [False for i in range(N)]


dup = False
for s, c in sc:
    if (not ans_l[s-1]) or ans_l[s-1] == str(c):
        if s > N or s < 1:
            out = True
            break
        ans_l[s-1] = str(c)
    else:
        dup = True
        break

# ans_l

for ix, x in enumerate(ans_l):
    if x:
        break
    ans_l[ix] = '1'

for ix, x in enumerate(ans_l):
    if x:
        pass
    else:
        ans_l[ix] = '0'

ans_n = int(''.join(ans_l))

ans_final = ans_n
if dup or out:
    ans_final = -1
if len(str(ans_n)) != N:
    ans_final = -1

print(str(ans_final))