#include <bits/stdc++.h>
using namespace std;
const int N = 55, mod = 1e9 + 7;
int n, p, a[N];
long long ans, pw[N], f[N][8];
inline int calc(int x, int y, int z) { return (x << 2) | (y << 1) | z; }
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  pw[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw[i] = pw[i - 1] * 2 % mod;
  }
  f[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 8; j++) {
      int x = (j >> 2) & 1, y = (j >> 1) & 1, z = j & 1;
      if (!f[i][j]) {
        continue;
      }
      if (a[i + 1] != 0) {
        if (z) {
          f[i + 1][calc(x, y, z)] =
              (f[i + 1][calc(x, y, z)] + f[i][j] * pw[i - 1] % mod) % mod;
          f[i + 1][calc(x ^ 1, 1, z)] =
              (f[i + 1][calc(x ^ 1, 1, z)] + f[i][j] * pw[i - 1] % mod) % mod;
        } else {
          f[i + 1][calc(x ^ 1, 1, z)] =
              (f[i + 1][calc(x ^ 1, 1, z)] + pw[i] * f[i][j] % mod) % mod;
        }
      }
      if (a[i + 1] != 1) {
        if (y) {
          f[i + 1][calc(x, y, z)] =
              (f[i + 1][calc(x, y, z)] + f[i][j] * pw[i - 1] % mod) % mod;
          f[i + 1][calc(x ^ 1, y, 1)] =
              (f[i + 1][calc(x ^ 1, y, 1)] + f[i][j] * pw[i - 1] % mod) % mod;
        } else {
          f[i + 1][calc(x ^ 1, y, 1)] =
              (f[i + 1][calc(x ^ 1, y, 1)] + pw[i] * f[i][j]) % mod;
        }
      }
    }
  }
  for (int j = 0; j < 4; j++) {
    ans = (ans + f[n][(p << 2) | j]) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
