n,m=map(int,input().split())
k=[0]*m
a=[0]*m
ans=["x"]*n

for i in range(m):
  k[i],a[i]=map(int,input().split())
  if k[i]==1 and n>2 and a[i]==0:
    print(-1)
    exit()
  
for i in range(m):
  for j in range(m):
    if k[i]==k[j]:
      if a[i]!=a[j]:
        print(-1)
        exit()
        
for i in range(m):
  ans[k[i]-1]=str(a[i])
  
Ans=""
for i in range(n):
  if ans[i]=="x":
    if i==0 and n>2:
      ans[i]="1"
    else:
      ans[i]="0"
  Ans+=ans[i]

if Ans=="0"*n and n>2:
  print(-1)
  exit()
        
print(int(Ans))