#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55, MOD = 1e9 + 7;
int n, p, c[MAXN], ans;
int f[MAXN][MAXN][MAXN][MAXN];
int pw[MAXN];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') && (f = -f), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline int explus(const int &a, const int &b) {
  return a + b >= MOD ? a + b - MOD : a + b;
}
inline void Explus(int &a, const int &b) {
  a = a + b >= MOD ? a + b - MOD : a + b;
}
int main() {
  n = read();
  p = read();
  f[0][0][0][0] = 1;
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) c[i] = read(), pw[i] = 2ll * pw[i - 1] % MOD;
  for (int i = 1; i <= n; ++i)
    for (int ob = 0; ob <= i; ++ob)
      for (int ow = 0; ob + ow <= i; ++ow)
        for (int eb = 0; eb + ob + ow <= i; ++eb) {
          int ew = i - ob - ow - eb;
          if (ob + eb && c[i] != 1) {
            int res = 0;
            if (ob) {
              if (ow)
                Explus(res, 1ll * f[i - 1][ob - 1][ow][eb] * pw[ow - 1] % MOD);
              else
                Explus(res, f[i - 1][ob - 1][ow][eb]);
            }
            if (eb && ow)
              Explus(res, 1ll * f[i - 1][ob][ow][eb - 1] * pw[ow - 1] % MOD);
            Explus(f[i][ob][ow][eb], 1ll * res * pw[ob + eb + ew - 1] % MOD);
          }
          if (ow + ew && c[i] != 0) {
            int res = 0;
            if (ow) {
              if (ob)
                Explus(res, 1ll * f[i - 1][ob][ow - 1][eb] * pw[ob - 1] % MOD);
              else
                Explus(res, f[i - 1][ob][ow - 1][eb]);
            }
            if (ob && ew)
              Explus(res, 1ll * f[i - 1][ob][ow][eb] * pw[ob - 1] % MOD);
            Explus(f[i][ob][ow][eb], 1ll * res * pw[ow + eb + ew - 1] % MOD);
          }
          if (i == n && ((ow + ob) % 2 == p)) Explus(ans, f[i][ob][ow][eb]);
        }
  printf("%d\n", ans);
  return 0;
}
