n,m = gets.chomp.split(" ").map(&:to_i)
a = Array.new(n,10)
m.times do
  s,c = gets.chomp.split(" ").map(&:to_i)
  a[s-1] = [a[s-1],c].min
end

if a[0] == 10
  puts -1
else
  str = ""
  a.each do |val|
    if val == 10
      str += "0"
    else
      str += val.to_s
    end
  end
  r = str.to_i
  if r.to_s.size != n
    puts -1
  else
    puts r
  end
end