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

D=['-1']*N

for sc in Sc:
    s,c=sc[0],sc[1]
    if s==1 and c==0 and N>1:
        print(-1)
        exit()
    if D[s-1]!='-1' and D[s-1]!=str(c):
        print(-1)
        exit()
    D[s-1]=str(c)
if D[0]=='-1':
    D[0]='1'
for i in range(1,N):
    if D[i]=='-1':
        D[i]='0'
 
print(''.join(D))
