N,M=map(int,input().split())
A=[-1]*N
L=[]
for j in range(M):
  L.append(list(map(int,input().split())))
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:
    print(-1)
    exit()
S=""
if N!=1 and A[0]==0:
  print(-1)
  exit()
for k in range(N):
  if A[k]==-1:
    if N!=1 and k==0:
      A[k]=1
    else:
      A[k]=0
  S+=str(A[i])
print(int(S))
  
