#include <bits/stdc++.h>
using namespace std;
int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; }
const int N = 55;
int n, p, c[N];
long long f[N][N][N][N];
long long ans = 0, pw[N], od[N], ev[N];
long long power(int u, int p) {
  if (p == 0) return 1;
  long long ret = power(u, p >> 1);
  (ret *= ret) %= 1000000007;
  if (p & 1) (ret *= u) %= 1000000007;
  return ret;
}
void init() {
  f[0][0][0][0] = 1;
  pw[0] = 1;
  ev[0] = 1;
  for (int i = 1; i < N; i++) {
    pw[i] = pw[i - 1] * 2 % 1000000007;
    od[i] = ev[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] % 1000000007 * od[ob] %
            1000000007) %= 1000000007;
  if (col != 0 && ow != 0)
    (ret += f[ob][eb][ow - 1][ew] * pw[ow - 1 + ew + eb] % 1000000007 * ev[ob] %
            1000000007) %= 1000000007;
  if (col != 1 && eb != 0)
    (ret += f[ob][eb - 1][ow][ew] * pw[ob + eb - 1 + ew] % 1000000007 * od[ow] %
            1000000007) %= 1000000007;
  if (col != 1 && ob != 0)
    (ret += f[ob - 1][eb][ow][ew] * pw[ob - 1 + eb + ew] % 1000000007 * ev[ow] %
            1000000007) %= 1000000007;
}
int main() {
  init();
  cin >> n >> p;
  for (int i = 1; i < n + 1; i++) scanf("%d", c + i);
  for (int i = 1; i < n + 1; i++)
    for (int ob = 0; ob < i + 1; ob++)
      for (int eb = 0; eb < i - ob + 1; eb++)
        for (int ow = 0; ow < i - ob - eb + 1; 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]) %= 1000000007;
        }
  printf("%lld\n", ans);
  return 0;
}
