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