n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=["X"]*n
for s,c in sc:
  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"
for i in range(n):
  if ans[i]!="0":
    break
  print(-1)
  exit()
ans="".join(ans)
ans=ans.replace("X", "0")
print(int(ans))