#include <bits/stdc++.h>
using namespace std;
int const MAX = 52;
int const MOD = 1e9 + 7;
int n, p;
int c[MAX];
int d[MAX][MAX][MAX][MAX];
int C[MAX][MAX];
int ans;
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int mult(int a, int b) { return (long long)a * b % MOD; }
int p2[MAX * MAX];
int C0[MAX];
int C1[MAX];
void init() {
  for (int i = 0; i <= MAX - 1; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
    }
  }
  for (int i = 0; i <= MAX - 1; i++) {
    for (int j = 0; j <= i; j += 2) {
      C0[i] = add(C0[i], C[i][j]);
    }
    for (int j = 1; j <= i; j += 2) {
      C1[i] = add(C1[i], C[i][j]);
    }
  }
  p2[0] = 1;
  for (int i = 1; i <= MAX * MAX - 1; i++) {
    p2[i] = add(p2[i - 1], p2[i - 1]);
  }
}
void solve() {
  d[1][0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int w = 0; w < i; w++) {
      for (int w1 = 0; w1 <= w; w1++) {
        for (int b1 = 0; b1 <= i - 1 - w; b1++) {
          if (!d[i][w][w1][b1]) continue;
          int w0 = w - w1;
          int b0 = (i - 1 - w) - b1;
          if (c[i] != 1) {
            {
              int nw1 = w1;
              int v1 = C1[b1];
              int v2 = p2[b0];
              int v3 = d[i][w][w1][b1];
              int v = mult(v1, mult(v2, v3));
              d[i + 1][w + 1][nw1][b1] = add(d[i + 1][w + 1][nw1][b1], v);
            }
            {
              int nw1 = w1 + 1;
              int v1 = C0[b1];
              int v2 = p2[b0];
              int v3 = d[i][w][w1][b1];
              int v = mult(v1, mult(v2, v3));
              d[i + 1][w + 1][nw1][b1] = add(d[i + 1][w + 1][nw1][b1], v);
            }
          }
          if (c[i] != 0) {
            {
              int nb1 = b1;
              int v1 = C1[w1];
              int v2 = p2[w0];
              int v3 = d[i][w][w1][b1];
              int v = mult(v1, mult(v2, v3));
              d[i + 1][w][w1][nb1] = add(d[i + 1][w][w1][nb1], v);
            }
            {
              int nb1 = b1 + 1;
              int v1 = C0[w1];
              int v2 = p2[w0];
              int v3 = d[i][w][w1][b1];
              int v = mult(v1, mult(v2, v3));
              d[i + 1][w][w1][nb1] = add(d[i + 1][w][w1][nb1], v);
            }
          }
        }
      }
    }
  }
  for (int w = 0; w <= n; w++) {
    for (int w1 = 0; w1 <= n; w1++) {
      for (int b1 = 0; b1 <= n; b1++) {
        if (!d[n + 1][w][w1][b1]) continue;
        if ((w1 + b1) % 2 != p) continue;
        int b = n - w;
        int v1 = d[n + 1][w][w1][b1];
        int v2 = p2[b * (b - 1) / 2];
        int v3 = p2[w * (w - 1) / 2];
        int v = mult(v1, mult(v2, v3));
        ans = add(ans, v);
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  init();
  scanf("%d %d", &n, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  solve();
  return 0;
}
