N,M=map(int,input().split())
C=[-1]*N
for i in range(M):
  s,c=map(int,input().split())
  s-=1
  if C[s]!=-1:
    if C[s]!=c:
      print(-1)
      exit(0)
  C[s]=c
  
if N>1 and C[0]==0:
  print(-1)
  exit(0)
  
ans=""
for i in range(len(C)):
  if C[i]==-1:
    ans+="0"
  else:
    ans+=str(C[i])
    
print(ans)
  
    