N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
Pa =[]
Pb =[]


if [1,0] in P:
  print(-1)
elif N == len(set(P[i][0] for i in range(M))):
  for i in range(M):
    if P[i][0] not in Pb:
      Pb.append(P[i][0])
      Pa.append(P[i][1]*(10**(N-P[i][0])))
  print(sum(Pa))
else:
 for l in range(M):
     for j in range(l+1,M):
         if P[l][0] == P[j][0] and P[l][1] != P[j][1]:
             print(-1)
             break
     else:
        continue
     break
 else:

     
  for k in range(1,N + 1):
    if k not in [P[i][0] for i in range(M)]:
      if k == 1:
        P.append([1,1])
      else:
        P.append([k,0])
  for i in range(M):
    if P[i][0] not in Pb:
      Pb.append(P[i][0])
      Pa.append(P[i][1]*(10**(N-P[i][0])))
  print(sum(Pa))

