n,m=map(int,input().split())
num=[0 for i in range(n)]
for i in range(m):
  s,c=map(int,input().split())
  if s>n:
    num[0]=-1
  if n>0 and s==1 and c==0:
    num[s-1]=-1
  elif num[s-1]==0 or num[s-1]==c:
    num[s-1]=c
  else:
    num[s-1]=-1 
if num[0]==0:
  if n>1:
    num[0]=1
#print('    ',num)
moji=''
if min(num)>=0:  
  for i in range(n):
    moji+=str(num[i])
  print(int(moji))
else:
  print(-1)