#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;
long long f[N][N][N];
long long ans = 0, pw[N], od[N], ev[N];
void init() {
  f[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 push_ans(int col, int ob, int ow, int e) {
  if (col != 0)
    (f[ob][ow + 1][e] += f[ob][ow][e] * pw[ow + e] % 1000000007 * ev[ob] %
                         1000000007) %= 1000000007;
  if (col != 1)
    (f[ob + 1][ow][e] += f[ob][ow][e] * pw[ob + e] % 1000000007 * ev[ow] %
                         1000000007) %= 1000000007;
  if (col != 1)
    (f[ob][ow][e + 1] += f[ob][ow][e] * pw[ob + e] % 1000000007 * od[ow] %
                         1000000007) %= 1000000007;
  if (col != 0)
    (f[ob][ow][e + 1] += f[ob][ow][e] * pw[ow + e] % 1000000007 * od[ob] %
                         1000000007) %= 1000000007;
}
int main() {
  init();
  cin >> n >> p;
  int c;
  for (int i = 0; i < n; i++) {
    scanf("%d", &c);
    for (int ob = 0; ob < i + 1; ob++)
      for (int ow = 0; ow < i - ob + 1; ow++) {
        push_ans(c, ob, ow, i - ob - ow);
      }
  }
  int i = n;
  for (int ob = 0; ob < i + 1; ob++)
    for (int ow = 0; ow < i - ob + 1; ow++) {
      int e = i - ob - ow;
      if (((ob + ow) & 1) == p) (ans += f[ob][ow][e]) %= 1000000007;
    }
  printf("%lld\n", ans);
  return 0;
}
