N,M=map(int,input().split())
A=[-1]*N
k=0
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]:
      k=1
      break
    else:
      continue
if (k==1) or (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))