n,m=map(int,input().split())
data=[input().split() for _ in range(m)]
ans=["0"]*n
for s,c in data:
  s=int(s)-1
  if ans[s]!="0" and ans[s]!=c:
    print(-1)
    exit()
  if n!=1 and s==0 and c=="0":
    print(-1)
    exit()
  ans[s]=c
if n!=1 and ans[0]=="0":
  ans[0]="1"
print("".join(ans))