loop do
    t = gets.to_i
    break if t == 0
    cycle = gets.split.map(&:to_i)

    table = [nil] * cycle.size
    table[0] = 0
    n = gets.to_i
    d0 = 1
    (1..n).each do
        d, t = gets.split.map(&:to_i)
        new_table = [nil] * cycle.size
        table.each.with_index do |m, i|
            j = (i + d - d0) % cycle.size
            new_table[j] = m if m && cycle[j] <= t
        end
        m = table.compact.min + 1
        new_table[0] = m if !new_table[0] || m < new_table[0]
        d0 = d
        table = new_table
    end

    puts table.compact.min
end