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