#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int mul(int x, int y) {
  long long z = 1LL * x * y;
  return z - z / mod * mod;
}
int f[2][51][51];
int fp[55];
int main() {
  int n, p, i, k, a, c, u, v, x, ans = 0;
  scanf("%d%d", &n, &p);
  for (i = fp[0] = 1; i <= n; i++) fp[i] = mul(fp[i - 1], 2);
  f[0][0][0] = 1;
  for (i = u = 0; i < n; i++) {
    v = u ^ 1;
    memset(f[v], 0, sizeof(f[v]));
    scanf("%d", &x);
    for (a = 0; a <= i; a++) {
      for (c = 0; a + c <= i; c++) {
        k = f[u][a][c];
        if (!k) continue;
        if (x != 0) {
          if (c) {
            add(f[v][a + 1][c], mul(k, fp[i - 1]));
            add(f[v][a][c], mul(k, fp[i - 1]));
          } else
            add(f[v][a + 1][c], mul(k, fp[i]));
        }
        if (x != 1) {
          if (a) {
            add(f[v][a][c + 1], mul(k, fp[i - 1]));
            add(f[v][a][c], mul(k, fp[i - 1]));
          } else
            add(f[v][a][c + 1], mul(k, fp[i]));
        }
      }
    }
    u ^= 1;
  }
  for (a = 0; a <= n; a++) {
    for (c = 0; a + c <= n; c++) {
      if ((a + c + p + 1) & 1) add(ans, f[u][a][c]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
