n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=[-1]*n
for i in sc:
  if ans[i[0]-1]==-1:
    ans[i[0]-1]=i[1]
  elif ans[i[0]-1]==i[1]:
    pass
  else:
    print(-1)
    exit()

if ans[0]==0:
  if n==1:
    print(0)
    exit()
  else:
    print(-1)
    exit()
elif ans[0]==-1:
  ans[0]="1"
  for i in range(1,len(ans)):
    if ans[i]==-1:
      ans[i]="0"
    else:
      ans[i]=str(ans[i])
  print("".join(ans))
else:
  for i in range(len(ans)):
    if ans[i]==-1:
      ans[i]="0"
    else:
      ans[i]=str(ans[i])
  print("".join(ans))