#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][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][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int w0 = 0; w0 <= i - 1; w0++)
      for (int w1 = 0; w1 <= i - 1 - w0; w1++)
        for (int b0 = 0; b0 <= i - 1 - w0 - w1; b0++) {
          int b1 = i - 1 - w0 - w1 - b0;
          if (a[i] != 1) {
            if (b1) {
              (f[i][w0][w1 + 1][b0] +=
               f[i - 1][w0][w1][b0] * pw[w0 + w1 + b0 + b1 - 1] % mo) %= mo;
              (f[i][w0 + 1][w1][b0] +=
               f[i - 1][w0][w1][b0] * pw[w0 + w1 + b0 + b1 - 1] % mo) %= mo;
            } else {
              (f[i][w0][w1 + 1][b0] +=
               f[i - 1][w0][w1][b0] * pw[w0 + w1 + b0] % mo) %= mo;
            }
          }
          if (a[i] != 0) {
            if (w1) {
              (f[i][w0][w1][b0] +=
               f[i - 1][w0][w1][b0] * pw[b0 + b1 + w0 + w1 - 1] % mo) %= mo;
              (f[i][w0][w1][b0 + 1] +=
               f[i - 1][w0][w1][b0] * pw[b0 + b1 + w0 + w1 - 1] % mo) %= mo;
            } else {
              (f[i][w0][w1][b0] +=
               f[i - 1][w0][w1][b0] * pw[b0 + b1 + w0] % mo) %= mo;
            }
          }
        }
  long long ans = 0;
  for (int w0 = 0; w0 <= n; w0++)
    for (int w1 = 0; w1 <= n - w0; w1++)
      for (int b0 = 0; b0 <= n - w0 - w1; b0++) {
        int b1 = n - w0 - w1 - b0;
        if ((w1 + b1) % 2 == p) (ans += f[n][w0][w1][b0]) %= mo;
      }
  printf("%lld\n", ans);
  return 0;
}
