N,M=map(int,input().split())
x=[-1]*N
for i in range(M):
    s,c=map(int,input().split())
    if x[s-1]==-1:
        x[s-1]=c
    elif x[s-1]!=c:
        print(-1)
        exit()
for a in range(N):
    if x[a]==-1:
        x[a]=0
print(*x,sep="")