N, M = map(int, input().split())
C=[list(map(int, input().split())) for i in range(M)]

#print(C)

sol = [-1] * N

for i in range(M):
    if C[i][0]==1 and C[i][1]==0:
        print(-1)
        exit()
    elif sol[C[i][0]-1]==-1:
        sol[C[i][0]-1]=C[i][1]  
    elif sol[C[i][0]-1]!=C[i][1]:
        print(-1)
        exit()

for j in range(N):
    if sol[j]==-1:
        sol[j]=0  

if sol[0]==0:
    sol[0]=1

solstr = [str(s) for s in sol]
print(int("".join(solstr)))
  