N , M = map(int,input().split())
sc = []
for i in range(M):
  new = list(map(int,input().split()))
  if i != 0:
    for j in range(len(sc)):
      if new[0] == sc[j][0]:
        if new[1] != sc[j][1]:
          print(-1)
          exit()
        else:
          break
      else:
        sc.append(new)
  else:
    sc.append(new)
    
ans = 0
for i in range(len(sc)):
  ans += sc[i][1] * (10**(sc[i][0]-1))
if len(str(ans)) == N:
  print(ans)
else:
  print(-1)