Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<iostream>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;


  string s;
  for (int i=0; i<n; i++) {
    char tmp;
    cin>>tmp;
    s+=tmp;
  }

  string ss1,ss2;
  bool flag=false;
  for (int i=0; i<m; i++) {
    int cnt=0;
    cin>>cnt;
    ss1+=string(cnt,'0'+(int)flag);
    ss2+=string(cnt,'0'+(int)!flag);
    flag=!flag;

  }
  // cout<<s<<endl;
  //cout<<ss1<<endl;
  //cout<<ss2<<endl;


  queue<pair<string,int> >qu;
  set<string> hash;
  qu.push(make_pair(s,0));

  while(!qu.empty())
    {
      string ss=qu.front().first;
      int cnt=qu.front().second;
      qu.pop();
      if(ss==ss1 || ss==ss2)
        {
          cout<<cnt<<endl;
          break;
        }
      for(int i=0;i<ss.size()-1;i++)
        {
          string tmp=ss;
          swap(tmp[i],tmp[i+1]);
          if(hash.count(tmp)==0)
            {
              hash.insert(tmp);
              qu.push(make_pair(tmp,cnt+1));
            }

        }
    }
  return 0;

}