N, M = gets.split(" ").map(&:to_i)
r = 0
R = [false,false,false]
M.times{
  s, c = gets.split(" ").map(&:to_i)
  if s == 1
    if c == 0
      puts -1
      exit
    end
  end
  if R[s-1] 
    k = r.div(10 ** (N-s)) % 10
    if k == c
     next
    end 
    puts -1
    exit
  end
  r = r + (10 ** (N-s)) * c
  R[s-1] = true
}
if (10 ** (N-1)) > r
  r = r + (10 ** (N-1))
end
puts r