#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int M = 1000000007;
int n, p, c[maxn];
long long ans = 0, pw[maxn], od[maxn], ev[maxn], f[maxn][maxn][maxn][maxn];
void init() {
  f[0][0][0][0] = 1;
  pw[0] = 1;
  for (int i = 1; i < maxn; i++) pw[i] = pw[i - 1] * 2 % M;
  ev[0] = 1, od[0] = 0;
  for (int i = 1; i < maxn; i++) ev[i] = od[i] = pw[i - 1];
}
void find_ans(int ob, int eb, int ow, int ew, int col, long long &ret) {
  if (col != 0 && ew != 0)
    (ret += f[ob][eb][ow][ew - 1] * pw[ow + ew - 1 + eb] % M * od[ob] % M) %= M;
  if (col != 0 && ow != 0)
    (ret += f[ob][eb][ow - 1][ew] * pw[ow + ew - 1 + eb] % M * ev[ob] % M) %= M;
  if (col != 1 && eb != 0)
    (ret += f[ob][eb - 1][ow][ew] * pw[ob + eb - 1 + ew] % M * od[ow] % M) %= M;
  if (col != 1 && ob != 0)
    (ret += f[ob - 1][eb][ow][ew] * pw[ob - 1 + eb + ew] % M * ev[ow] % M) %= M;
  return;
}
int main() {
  init();
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", c + i);
  for (int i = 1; i <= n; i++)
    for (int ob = 0; ob <= i; ob++)
      for (int eb = 0; ob + eb <= i; eb++)
        for (int ow = 0; ob + eb + ow <= i; ow++) {
          int ew = i - ob - eb - ow;
          find_ans(ob, eb, ow, ew, c[i], f[ob][eb][ow][ew]);
          if (i == n && ((ob + ow) & 1) == p) (ans += f[ob][eb][ow][ew]) %= M;
        }
  printf("%I64d", ans);
  return 0;
}
