N,M=map(int,input().split())

Q=[]

for i in range(M):
    s,c=map(int,input().split())
    Q.append([s,c])

Q.sort()
Q1=[]
for i in range(M-1):
    if Q[i][0]==Q[i+1][0]:
        if Q[i][1]!=Q[i+1][1]:
            print(-1)
            exit()


S=["0"]*N
S[0]="1"

for i in range(M):
    S[Q[i][0]-1]=str(Q[i][1])

if S[0]=="0":
    print(-1)
    exit()

ans=""
for i in range(N):
    ans+=S[i]

print(ans)
