N, M = map(int, input().split())
ans_list=[]
S=[]
C=[]
ans=0
for i in range(M):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for n in range(1000):
  if n < N:
    break
  for i, s in enumerate(S):
    n = str(n)
    if n[s-1] == C[i]:
      continue
    else:
      ans = -1
      break
      
  ans_list.append(int(n))
  
if ans != -1:
  ans=min(ans_list)
  
print(ans)
  