n,m = map(int,input().split())
ans = [99]*n
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == 99 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if (ans[0] == 99 or ans[0] == 0) and n != 1:
    print(-1)
    exit()
for i in range(n):
    if ans[i] == 99:
        ans[i] = 0


print("".join([str(i) for i in ans]))