s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[1])]
a=''
b=0
u=list(map(list,set(map(tuple,t))))
u=(sorted(u,key=lambda x: x[0]))
x=[0]*s[0]
for i in range(len(u)):
  c=t[i][0]-1
  if x[c]==0:
    x[c]+=t[i][1]+10
  else:
    b=1
if b==1:
  print(-1)
else:
  x.reverse()
  for j in range(s[0]):
    if x[j]==0:
      if j==0:
        a='1'+a
      else:
        a='0'+a
    else:
      x[j]=x[j]-10
      if j==0 and x[j]==0:
        a='1'+a
      else:
        a=str(x[j])+a
  print(a)