import sys
N,M=map(int,input().split())
listSC=[]  
for k in range(M):
  s,c=map(int,input().split())
  listSC+=[[s,c]]
for i in range(10**(N-1),10**N):
  A=list(str(i))
  for k in range(M):
    if A[listSC[k][0]-1]!=str(listSC[k][1]):
      break
    if k==M-1:
      ans=i
      print(ans)
      sys.exit()
  if i==10**N-1:
    print(-1)