#include <bits/stdc++.h>
using namespace std;
const long long N = 55;
long long read() {
  long long x = 0, tmp = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') tmp = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return tmp * x;
}
const long long mod = 1e9 + 7;
long long n, p, a[N], pow2[N];
long long f[N][2][2][2];
signed main() {
  n = read();
  p = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  pow2[0] = 1;
  for (long long i = 1; i <= n; i++)
    pow2[i] = (pow2[i - 1] + pow2[i - 1]) % mod;
  f[0][0][0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long black = 0; black < 2; black++)
      for (long long white = 0; white < 2; white++)
        for (long long par = 0; par < 2; par++) {
          long long lans = f[i - 1][black][white][par];
          if (!lans) continue;
          if (a[i] != 0) {
            if (!black)
              (f[i][0][1][par ^ 1] += lans * pow2[i - 1] % mod) %= mod;
            else {
              (f[i][1][1][par ^ 1] += lans * pow2[i - 2] % mod) %= mod;
              (f[i][1][white][par] += lans * pow2[i - 2] % mod) %= mod;
            }
          }
          if (a[i] != 1) {
            if (!white)
              (f[i][1][0][par ^ 1] += lans * pow2[i - 1] % mod) %= mod;
            else {
              (f[i][1][1][par ^ 1] += lans * pow2[i - 2] % mod) %= mod;
              (f[i][black][1][par] += lans * pow2[i - 2] % mod) %= mod;
            }
          }
        }
  }
  long long res = 0;
  for (long long black = 0; black < 2; black++)
    for (long long white = 0; white < 2; white++)
      res = (res + f[n][black][white][p]) % mod;
  printf("%d\n", res);
  return 0;
}
