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()
ans = ''.join(ans).replace('*', "0")
print(ans if ans[0] != '0' else -1)
