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