#include <bits/stdc++.h>
using namespace std;
const int maxn = 50, mod = 1e9 + 7;
int dp[maxn + 5][maxn + 5][maxn + 5][maxn + 5];
int c[maxn + 5];
int n, p;
int pw[maxn + 5];
void inc(int& a, int b) { a = (a + b) % mod; }
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  pw[0] = 1;
  for (int i = 1; i <= maxn; ++i) pw[i] = pw[i - 1] * 2LL % mod;
  if (c[1] == 0 || c[1] == -1) dp[1][0][0][0] = 1;
  if (c[1] == 1 || c[1] == -1) dp[1][0][1][0] = 1;
  for (int i = 2; i <= n; ++i)
    for (int ew = 0; ew <= i; ++ew)
      for (int ow = 0; ow <= i; ++ow)
        for (int eb = 0; eb <= i; ++eb) {
          if (ow + ew + eb > i) continue;
          int ob = i - ew - ow - eb;
          if (c[i] == 1 || c[i] == -1) {
            if (ow + ew != 0) {
              long long s = 0;
              if (ow >= 1)
                if (ob == 0)
                  s = dp[i - 1][ew][ow - 1][eb];
                else
                  s = 1LL * pw[ob - 1] * dp[i - 1][ew][ow - 1][eb] % mod;
              if (ew >= 1)
                if (ob >= 1)
                  s += 1LL * pw[ob - 1] * dp[i - 1][ew - 1][ow][eb] % mod;
              s %= mod;
              s = s * pw[eb + ew + ow - 1] % mod;
              inc(dp[i][ew][ow][eb], (int)s);
            }
          }
          if (c[i] == 0 || c[i] == -1) {
            if (ob + eb != 0) {
              long long s = 0;
              if (ob >= 1)
                if (ow == 0)
                  s = dp[i - 1][ew][ow][eb];
                else
                  s = 1LL * pw[ow - 1] * dp[i - 1][ew][ow][eb] % mod;
              if (eb >= 1)
                if (ow >= 1)
                  s += 1LL * pw[ow - 1] * dp[i - 1][ew][ow][eb - 1] % mod;
              s %= mod;
              s = s * pw[eb + ob + ew - 1] % mod;
              inc(dp[i][ew][ow][eb], (int)s);
            }
          }
        }
  int ans = 0;
  for (int ew = 0; ew <= n; ++ew)
    for (int ow = 0; ow <= n; ++ow)
      for (int eb = 0; eb <= n; ++eb)
        if (ew + ow + eb <= n)
          if ((ow + n - ew - ow - eb) % 2 == p) inc(ans, dp[n][ew][ow][eb]);
  printf("%d\n", ans);
  return 0;
}
