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