def swap(b,e)
    return Float::INFINITY if b.count("0") != e.count("0")
    i = 0
    ret = 0
    while i < b.length
        if b[i] == e[i]
            i += 1
            next
        end
        j = i + 1
        while b[j] == b[i]
            j += 1
        end
        ret += j - i
        b[i], b[j] = b[j], b[i]
        i += 1
    end
    return ret
end

n, m = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
s0 = ""
s1 = ""
p.each_slice(2) do |d|
    if d.size == 2
        s0 << "0" * d[0]
        s0 << "1" * d[1]
    else
        s0 << "0" * d[0]
    end
end
p.each_slice(2) do |d|
    if d.size == 2
        s1 << "1" * d[0]
        s1 << "0" * d[1]
    else
        s1 << "1" * d[0]
    end
end
puts [swap(b.join,s0), swap(b.join,s1)].min