Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
# -*- coding: utf-8 -*-

( n, m ) = map ( int, input ( ).split ( ) )
b = tuple ( map ( int, input ( ).split ( ) ) )
p = list ( map ( int, input ( ).split ( ) ) )

cs = 0
ss = { }
fs = [ ]
bs = [ b ]
while bs:
  ( fs, bs ) = ( bs, fs )
  while fs:
    b = fs.pop ( )
    if b not in ss:
      ss[ b ] = cs
      b = list ( b )
      for i in range ( n - 1 ):
        ( b[ i ], b[ i + 1 ] ) = ( b[ i + 1 ], b[ i ] )
        bs.append ( tuple ( b ) )
        ( b[ i + 1 ], b[ i ] ) = ( b[ i ], b[ i + 1 ] )
  cs = cs + 1

for ( k, v ) in ss.items ( ):
  res = [ ]
  co = 1
  for i in range ( 1, len ( k ) ):
    if k[ i - 1 ] == k[ i ]:
      co = co + 1
    else:
      res.append ( co )
      co = 1
  res.append ( co )
  if res == p and v < cs:
    cs = v

print ( cs )