n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=["X"]*n
if m==0:
  if n==1:
    print(0)
  elif n==2:
    print(10)
  elif n==3:
    print(100)
  exit()

for s,c in sc:
  if s>n:
    print(-1)
    exit()
  if ans[s-1]=="X" or ans[s-1]==str(c):
    ans[s-1]=str(c)
  else:
    print(-1)
    exit()
if ans[0]=="X":
  ans[0]="1"
if ans[0]=="0":
  print(-1)
  exit()
ans="".join(ans)
ans=ans.replace("X", "0")
print(int(ans))
