Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int main(){
    int n,m;
    while(cin >> n >> m && n){
        vi b(n), p(m);
        rep(i,n) cin >> b[i];
        rep(i,m) cin >> p[i];
        queue<pair<int,vi>> q;
        q.emplace(0,b);
        set<vi> dp;
        while(q.size()){
            int step; vi b;
            tie(step,b) = q.front();
            q.pop();
            vi seq = {1};
            rep(i,b.size()-1){
                if(b[i]==b[i+1])seq.back()++;
                else seq.pb(1);
            }
            if(seq==p){
                cout << step << endl;
                break;
            }
            rep(i,b.size()-1){
                swap(b[i],b[i+1]);
                if(!dp.count(b)){
                    dp.insert(b);
                    q.emplace(step+1,b);
                }
                swap(b[i],b[i+1]);
            }
        }
    }
}