N, M = map(int, input().split())
ans = ['*'] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] == '*':
        ans[s - 1] = str(c)
    elif ans[s - 1] != str(c):
        print(-1)
        exit()
if ans[0] == '*':
    ans[0] = '1'
print(''.join(ans).replace('*', '0') if ans[0] != '0' else -1)
