N, M = gets.split.map(&:to_i)
nums = Array.new(N)
lists = []
M.times do
  lists << gets.split.map(&:to_i)
end

((10 ** (N - 1))..(10 ** N - 1)).each do |t|
  check = true
  s = t.to_s
  lists.each do |list|
    if s[list[0] - 1] != "#{list[1]}"
      check = false
    end
  end
  if check
    puts t
    exit
  end
end
puts -1