#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int mod = 1E9 + 7;
long long Pow(long long v, int p) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = (ret * v) % mod;
    p >>= 1;
    v = (v * v) % mod;
  }
  return ret;
}
long long Div(long long a, long long b) { return (a * Pow(b, mod - 2)) % mod; }
long long Pc[maxn];
long long C(int r, int k) { return Div(Pc[r], (Pc[k] * Pc[r - k]) % mod); }
long long T[maxn][2];
long long dp[maxn][maxn][maxn][maxn];
int N, P, D[maxn];
int main() {
  Pc[0] = 1;
  for (int i = 1; i < maxn; ++i) Pc[i] = (Pc[i - 1] * i) % mod;
  for (int i = 0; i < maxn; ++i)
    for (int d = 0; d < 2; ++d) {
      for (int k = 0; 2 * k + d <= i; ++k) {
        T[i][d] += C(i, 2 * k + d);
      }
    }
  scanf("%d%d", &N, &P);
  for (int i = 1; i <= N; ++i) scanf("%d", D + i);
  dp[0][0][0][0] = 1;
  for (int i = 0; i <= N; ++i) {
    for (int ew = 0; ew <= i; ++ew)
      for (int ow = 0; ow + ew <= i; ++ow)
        for (int eb = 0; ew + ow + eb <= i; ++eb) {
          int ob = i - ew - ow - eb, u = i + 1;
          if (D[u] == 1 || D[u] == -1) {
            long long t = Pow(2, ew + ow + eb), o = (T[ob][0] * t) % mod,
                      e = (T[ob][1] * t) % mod;
            dp[u][ew + 1][ow][eb] += (e * dp[i][ew][ow][eb]) % mod;
            if (dp[u][ew + 1][ow][eb] >= mod) dp[u][ew + 1][ow][eb] -= mod;
            dp[u][ew][ow + 1][eb] += (o * dp[i][ew][ow][eb]) % mod;
            if (dp[u][ew][ow + 1][eb] >= mod) dp[u][ew][ow + 1][eb] -= mod;
          }
          if (D[u] == 0 || D[u] == -1) {
            long long t = Pow(2, ew + eb + ob), o = (T[ow][0] * t) % mod,
                      e = (T[ow][1] * t) % mod;
            dp[u][ew][ow][eb + 1] += (e * dp[i][ew][ow][eb]) % mod;
            if (dp[u][ew][ow][eb + 1] >= mod) dp[u][ew][ow][eb + 1] -= mod;
            dp[u][ew][ow][eb] += (o * dp[i][ew][ow][eb]) % mod;
            if (dp[u][ew][ow][eb] >= mod) dp[u][ew][ow][eb] -= mod;
          }
        }
  }
  long long ans = 0;
  for (int ew = 0; ew <= N; ++ew)
    for (int ow = 0; ow + ew <= N; ++ow)
      for (int eb = 0; ew + ow + eb <= N; ++eb) {
        int ob = N - ew - ow - eb;
        if ((ow + ob) % 2 == P) {
          ans += dp[N][ew][ow][eb];
          if (ans >= mod) ans -= mod;
        }
      }
  cout << ans << endl;
}
