a1=[]
a2=[]
a3=[]
d=0
N,M=map(int, input().split())
for i in range(M):
 s,c=map(int, input().split())
 if N-s+1==3:
  if a1==[]:
   if c==0:
    if s==1:
     d+=1
    else:
     a1.append(c)
   else:
    a1.append(c)
  else:
   if c in a1:
    continue
   else:
    d+=1
 elif N-s+1==2:
  if a2==[]:
   if c==0:
    if s==2:
     d+=1
    else:
     a2.append(c)
   else:
    a2.append(c)
  else:
   if c in a2:
    continue
   else:
    d+=1
 else:
  if a3==[]:
   a3.append(c)
  else:
   if c in a3:
    continue
   else:
    d+=1
if a1==[]:
 a1.append(0)
if a2==[]:
 a2.append(0)
if a3==[]:
 a3.append(0)
if d>=1:
 print(-1)
else:
 if N==1:
  print(a3[0])
 elif N==2:
  print(a2[0]*10+a3[0])
 else:
  print(a1[0]*100+a2[0]*10+a3[0])