[N,M]=[int(i) for i in input().split()]
lis=[-1 for i in range(N)]
flg=0
for m in range(M):
  [s,c]=[int(i) for i in input().split()]
  if lis[s-1]==-1 or lis[s-1]==c:
    lis[s-1]=c
  else:
    flg=1
    break
x=""
if flg==1:
  print("-1")
else:
  for i in range(len(lis)):
    if i==0 and lis[i]==0:
      print("-1")
      for i in range(10**20):
      	flg+=i
      break
    if lis[i]==-1:
      if flg==0:
        x+="1"
        flg=2
      else:
        x+="0"
    else:
      x+=str(lis[i])
      flg="2"
    if i==len(lis)-1:print(x)