#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int mo = (int)1e9 + 7;
int n, p, a[N];
long long pw[N], f[N][N][N];
int main() {
  pw[0] = 1;
  for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * 2 % mo;
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  f[0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int wb0 = 0; wb0 <= i - 1; wb0++)
      for (int w1 = 0; w1 <= i - 1 - wb0; w1++) {
        int b1 = i - 1 - wb0 - w1;
        if (a[i] != 1) {
          if (b1) {
            (f[i][wb0][w1 + 1] +=
             f[i - 1][wb0][w1] * pw[wb0 + w1 + b1 - 1] % mo) %= mo;
            (f[i][wb0 + 1][w1] +=
             f[i - 1][wb0][w1] * pw[wb0 + w1 + b1 - 1] % mo) %= mo;
          } else {
            (f[i][wb0][w1 + 1] += f[i - 1][wb0][w1] * pw[wb0 + w1] % mo) %= mo;
          }
        }
        if (a[i] != 0) {
          if (w1) {
            (f[i][wb0][w1] += f[i - 1][wb0][w1] * pw[wb0 + b1 + w1 - 1] % mo) %=
                mo;
            (f[i][wb0 + 1][w1] +=
             f[i - 1][wb0][w1] * pw[wb0 + b1 + w1 - 1] % mo) %= mo;
          } else {
            (f[i][wb0][w1] += f[i - 1][wb0][w1] * pw[wb0 + b1] % mo) %= mo;
          }
        }
      }
  long long ans = 0;
  for (int wb0 = 0; wb0 <= n; wb0++)
    for (int w1 = 0; w1 <= n - wb0; w1++) {
      int b1 = n - wb0 - w1;
      if ((w1 + b1) % 2 == p) (ans += f[n][wb0][w1]) %= mo;
    }
  printf("%lld\n", ans);
  return 0;
}
