#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const long long mod = 1e9 + 7;
long long fastPow(long long x, long long p) {
  long long ans = 1, curr = x;
  while (p != 0) {
    if (p % 2 != 0) ans = (ans * curr) % mod;
    p /= 2;
    curr = (curr * curr) % mod;
  }
  return ans;
}
long long inv(long long x) { return fastPow(x, mod - 2); }
long long dp[MAXN][MAXN][MAXN][MAXN];
long long fact[MAXN], invFact[MAXN];
long long comb(int n, int k) {
  if (n == 0 || k == 0) return 1;
  return (((fact[n] * invFact[k]) % mod) * invFact[n - k]) % mod;
}
long long p2[MAXN];
long long evenComb[MAXN], oddComb[MAXN];
void Init() {
  fact[0] = invFact[0] = 1;
  for (int i = 1; i <= 50; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    invFact[i] = inv(fact[i]);
  }
  p2[0] = 1;
  for (int i = 1; i <= 50; i++) p2[i] = (p2[i - 1] * 2) % mod;
  for (int i = 0; i <= 50; i++) {
    for (int j = 0; j <= i; j++) {
      if (j % 2 == 0)
        evenComb[i] += comb(i, j);
      else
        oddComb[i] += comb(i, j);
    }
    oddComb[i] %= mod;
    evenComb[i] %= mod;
  }
}
long long calcState(int ew, int ow, int eb, int ob, int col) {
  long long answer = 0;
  if (col != 0 && ew != 0)
    answer += (((dp[ew - 1][ow][eb][ob] * p2[ew - 1 + ow + eb]) % mod) *
               oddComb[ob]) %
              mod;
  if (col != 0 && ow != 0)
    answer += (((dp[ew][ow - 1][eb][ob] * p2[ew + ow - 1 + eb]) % mod) *
               evenComb[ob]) %
              mod;
  if (col != 1 && eb != 0)
    answer += (((dp[ew][ow][eb - 1][ob] * p2[eb - 1 + ob + ew]) % mod) *
               oddComb[ow]) %
              mod;
  if (col != 1 && ob != 0)
    answer += (((dp[ew][ow][eb][ob - 1] * p2[eb + ob - 1 + ew]) % mod) *
               evenComb[ow]) %
              mod;
  return answer % mod;
}
int n, p;
int c[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> p;
  for (int i = 1; i <= n; i++) cin >> c[i];
  Init();
  dp[0][0][0][0] = 1;
  long long answer = 0;
  for (int i = 1; i <= n; i++) {
    for (int ew = 0; ew <= i; ew++) {
      for (int ow = 0; ow + ew <= i; ow++) {
        for (int eb = 0; eb + ow + ew <= i; eb++) {
          int ob = i - ew - ow - eb;
          dp[ew][ow][eb][ob] = calcState(ew, ow, eb, ob, c[i]);
          if (i == n && (ow + ob) % 2 == p) answer += dp[ew][ow][eb][ob];
        }
      }
    }
  }
  cout << answer % mod << '\n';
}
