#include <bits/stdc++.h>
using namespace std;
namespace my_std {
const long long inf = 0x3f3f3f3f;
const long long inff = 1e15;
inline long long read() {
  long long sum = 0, f = 1;
  char ch = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    sum = sum * 10 + (ch ^ 48);
    ch = getchar();
  }
  return sum * f;
}
inline void write(long long x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
inline void writesp(long long x) {
  write(x);
  putchar(' ');
}
}  // namespace my_std
using namespace my_std;
const long long N = 55, mod = 1e9 + 7;
long long n, p, a[N], f[N][N][N][N], mi[N] = {1}, ans;
int main(void) {
  n = read(), p = read();
  for (register long long i = (1); i <= (n); ++i) a[i] = read();
  for (register long long i = (1); i <= (n); ++i)
    mi[i] = (mi[i - 1] << 1) % mod;
  if (a[1] == 1 || a[1] == -1) {
    f[1][1][0][0] = 1;
    if (p && n == 1) ans++;
  }
  if (!a[1] || a[1] == -1) {
    f[1][0][1][0] = 1;
    if (p && n == 1) ans++;
  }
  for (register long long i = (2); i <= (n); ++i)
    for (register long long jb = (0); jb <= (i); ++jb)
      for (register long long jh = (0); jh <= (i - jb); ++jh)
        for (register long long ob = (0); ob <= (i - jb - jh); ++ob) {
          long long oh = i - jb - jh - ob;
          if (a[i] == 1 || a[i] == -1) {
            long long add = 0;
            if ((jb + ob) != 0) {
              if (jb != 0) {
                if (jh == 0)
                  add = (add + f[i - 1][jb - 1][jh][ob]) % mod;
                else
                  add = (add + mi[jh - 1] * f[i - 1][jb - 1][jh][ob]) % mod;
              }
              if (ob != 0 && jh != 0)
                add = (add + mi[jh - 1] * f[i - 1][jb][jh][ob - 1] % mod);
            }
            add = (add * mi[jb + ob + oh - 1]) % mod;
            f[i][jb][jh][ob] = (f[i][jb][jh][ob] + add) % mod;
          }
          if (a[i] == 0 || a[i] == -1) {
            long long add = 0;
            if ((jh + oh) != 0) {
              if (jh != 0) {
                if (jb == 0)
                  add = (add + f[i - 1][jb][jh - 1][ob]) % mod;
                else
                  add = (add + mi[jb - 1] * f[i - 1][jb][jh - 1][ob]) % mod;
              }
              if (jb != 0 && oh != 0)
                add = (add + mi[jb - 1] * f[i - 1][jb][jh][ob] % mod) % mod;
            }
            add = (add * mi[jh + ob + oh - 1]) % mod;
            f[i][jb][jh][ob] = (f[i][jb][jh][ob] + add) % mod;
          }
          if (i == n && (jb + jh) % 2 == p)
            ans = (ans + f[i][jb][jh][ob]) % mod;
        }
  writeln(ans);
  return 0;
}
