Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define im imag()
#define re real()
#define r(I, N) for(int I=0;I<N;I++)
#define f(I, A, B) for(int I=A;I<B;I++)
#define fd(I, A, B) for(int I=A;I>=B;I--)
#define ite(x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define sz(x) ((int)(x).size())
#define clr(x) memset(x, 0, sizeof(x))

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef complex<ld> Point;
typedef Point Vector;

const ld pi = acos(-1.0);
const ld eps = 1e-12;

int N, M;
int r[20], a[20], b[20];

int main()
{
      cin >> N >> M;
      r(i, N) cin >> a[i], b[i] = a[i];
      r(i, M) cin >> r[i];

      /// Case 1 : 0

      int pt = 0, num = 0, ans1 = 0, ans2 = 0;

      bool flag1 = true;

      r(i, N)
      {
            f(j, i, i + r[pt])
            {
                  if(a[j] != num)
                  {
                        int rt = j;
                        while(a[rt] != num && rt < N) rt++;
                        if(rt >= N)
                        {
                              flag1 = false;
                              break;
                        }
                        swap(a[rt], a[j]);
                        ans1 += rt - j;
                  }
            }
            i += r[pt++] - 1;
            num = !num;
      }

      /// Case 2 : 1
      bool flag2 = true;
      num = 1;
      pt = 0;

      r(i, N)
      {
            f(j, i, i + r[pt])
            {
                  if(b[j] != num)
                  {
                        int rt = j;
                        while(b[rt] != num && rt < N) rt++;
                        if(rt >= N)
                        {
                              flag2 = false;
                              break;
                        }
                        swap(b[rt], b[j]);
                        ans2 += rt - j;
                  }
            }
            i += r[pt++] - 1;
            num = !num;
      }
      if(flag1 && !flag2) cout << ans1 << endl;
      else if(!flag1 && flag2) cout << ans2<< endl;
      else cout << min(ans1, ans2) << endl;
      return 0;
}