def main():
  n,m = map(int,input().split())
  s = []
  c = []
  ans = 0
  for i in range(m):
      temp_s,temp_c = map(int,input().split())
      if n==1 and temp_s==1 and temp_c==0:
          continue
      if temp_s==1 and temp_c==0 :
          print(-1)
          return
      if temp_s in s:
          if c[s==temp_s] != temp_c:
              print(-1)
              return
      else:
          s.append(temp_s)
          c.append(temp_c)
          ans += temp_c * (10**(n-temp_s))
      #print(temp_s,temp_c,ans)

  if ans < 10**(n-1) and n > 2:
    print(-1)
    return
    
  print(ans)
  return

main()