def swap(s, t, n)
  ret = 0
  n.times do |i|
    if s[i] != t[i]
      k = s[i..-1].index(1 - s[i])
      s.slice!(i + k)
      s.insert(i, t[i])
      ret += k
    end
  end
  ret
end

def turn(t)
  t.map{|i| 1 - i}
end

n, m = gets.split.map(&:to_i)
s = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

t = []
bit = 0
b.each{ |i| i.times{ t << bit }; bit = 1 - bit }
ans = swap(s.dup, t, n) if s.count(0) == t.count(0)
if s.count(0) == turn(t).count(0) && ans > (ret = swap(s, turn(t), n))
  ans = ret
end
p ans