#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 50;
const int MOD = 1000000007;
int n, wantpar;
int fixedcol[MAXN];
int dp[MAXN + 1][MAXN + 1][MAXN + 1][MAXN + 1];
int p2[MAXN + 1];
int C[MAXN + 1][MAXN + 1];
int fac[MAXN + 1];
int wayspar[MAXN + 1][2];
void inc(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}
void run() {
  scanf("%d%d", &n, &wantpar);
  for (int i = (0); i < (n); ++i) scanf("%d", &fixedcol[i]);
  p2[0] = 1;
  for (int i = (1); i <= (n); ++i) p2[i] = (long long)p2[i - 1] * 2 % MOD;
  for (int i = (0); i <= (n); ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = (1); j < (i); ++j)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
  }
  fac[0] = 1;
  for (int i = (1); i <= (n); ++i) fac[i] = (long long)fac[i - 1] * i % MOD;
  for (int i = (0); i <= (n); ++i)
    for (int j = (0); j <= (i); ++j) inc(wayspar[i][j % 2], C[i][j]);
  int ret = 0;
  memset(dp, 0, sizeof(dp));
  dp[0][0][0][0] = 1;
  for (int bevn = (0); bevn <= (n); ++bevn)
    for (int bodd = (0); bodd <= (n); ++bodd)
      for (int wevn = (0); wevn <= (n); ++wevn)
        for (int wodd = (0); wodd <= (n); ++wodd) {
          int cways = dp[bevn][bodd][wevn][wodd],
              ccnt = bevn + bodd + wevn + wodd;
          if (ccnt == n && (bodd + wodd) % 2 == wantpar) inc(ret, cways);
          if (cways == 0 || ccnt >= n) continue;
          for (int ncol = (0); ncol < (2); ++ncol) {
            if (fixedcol[ccnt] != -1 && fixedcol[ccnt] != ncol) continue;
            for (int npar = (0); npar < (2); ++npar) {
              int na = ncol == 0 ? bevn + bodd + wevn : wevn + wodd + bevn,
                  nb = ccnt - na;
              int nways =
                  (long long)cways * p2[na] % MOD * wayspar[nb][1 - npar] % MOD;
              inc(dp[bevn + (ncol == 0 && npar == 0 ? 1 : 0)]
                    [bodd + (ncol == 0 && npar == 1 ? 1 : 0)]
                    [wevn + (ncol == 1 && npar == 0 ? 1 : 0)]
                    [wodd + (ncol == 1 && npar == 1 ? 1 : 0)],
                  nways);
            }
          }
        }
  printf("%d\n", ret);
}
int main() {
  run();
  return 0;
}
