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