n,m=map(int,input().split())
l=[-1]*n
flag=True
for i in range(m):
  s,c=map(int,input().split())
  if l[s-1]<0:
    l[s-1]=c
  elif l[s-1]!=c:
    flag=False
if flag==False:
  print(-1)
elif n>1 and l[0]==0:
  print(-1)
elif n>1 and l[0]!=0:
  l[0]=1
  for j in range(1,n):
    if l[j]<0:
      l[j]=0
  ans="".join(map(str,l))
  print(int(ans))
elif n==1 and l[0]<0:
  print(0)
else:
  print(int(l[0]))
  