import sys
n,m = map(int,input().split())
ans = [0] * n
print(ans)
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] != 0 and ans[s-1] != c:
        print(-1)
        sys.exit()
    ans[s-1] = c
t=""
for i in ans:
    t += str(i)
t = int(t)
if len(str(t)) != n:
    print(-1)
    sys.exit()
print(int(t))