import numpy as np
N,M=map(int,input().split())
A=np.zeros(N)
ans=0
for i in range(M):
  s,t=map(int,input().split())
  if s==1 and t==0:
    ans=1
  elif t==0:
    A[s-1]=99
  else:
    if A[s-1]==0:
      A[s-1]=t
    elif A[s-1]==t:
      A[s-1]=t
    else:
      ans=1
if N!=1:      
  if A[0]==0:
    A[0]=1

if ans==1:
  print(-1)
else:
  for i in range(N):
    if A[i]==99:
      A[i]=0
    ans+=A[i]*(10**(N-i-1))
  print(int(ans))
  