import sys
N,M=map(int,input().split())
A=[-1 for _ in range(N)]

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