N, M = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for _ in range(M)]
ans = ["0"]*N
f = [False]*N
for s, c in sc:
    s -= 1
    c = str(c)
    if f[s] and ans[s] != c:
        break
    f[s] = True
    ans[s] = c
else:
    if not(N != 1 and ans[0] == '0'):
        print(''.join(ans))
    else:
        ans[0] = '1'
        print(''.join(ans))
    exit()

print(-1)
