N,M=map(int,input().split())
A=[-1]*N
for i in range(M):
  L=list(map(int,input().split()))
  if A[L[0]-1]==-1:
    A[L[0]-1]=L[1]
  else:
    if A[L[0]-1]==L[1]:
      continue
    else:
      print(-1)
      exit()
if N!=1 and A[0]==0:
  print(-1)
else:
  S=""
  if A[0]==-1:
    A[0]=1
  
  if N!=1:
    for i in range(N):
      if A[i]==-1:
        A[i]=0
      S+=str(A[i])
    print(int(S))
  else:
    print(int(A[0])
