#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  if (flag) x = -x;
}
using namespace std;
const int P = 1e9 + 7;
long long mi[123];
int n, tp[123], p;
inline void init() {
  const int up = n + 5;
  mi[0] = 1;
  for (int i = 1; i <= up; ++i) mi[i] = mi[i - 1] * 2 % P;
}
long long f[123][2][2][2];
inline void work() {
  f[n + 1][0][0][0] = 1;
  for (int i = n; i; --i) {
    for (int a = 0; a < 2; ++a) {
      for (int b = 0; b < 2; ++b) {
        for (int c = 0; c < 2; ++c)
          if (f[i + 1][a][b][c]) {
            long long tmp = f[i + 1][a][b][c];
            if (tp[i] != 1) {
              if (!b) {
                f[i][1][b][c ^ 1] = (f[i][1][b][c ^ 1] + tmp * mi[n - i]) % P;
              } else {
                f[i][1][b][c ^ 1] =
                    (f[i][1][b][c ^ 1] + tmp * mi[n - i - 1]) % P;
                f[i][a][b][c] = (f[i][a][b][c] + tmp * mi[n - i - 1]) % P;
              }
            }
            if (tp[i] != 0) {
              if (!a) {
                f[i][a][1][c ^ 1] = (f[i][a][1][c ^ 1] + tmp * mi[n - i]) % P;
              } else {
                f[i][a][1][c ^ 1] =
                    (f[i][a][1][c ^ 1] + tmp * mi[n - i - 1]) % P;
                f[i][a][b][c] = (f[i][a][b][c] + tmp * mi[n - i - 1]) % P;
              }
            }
          }
      }
    }
  }
  long long res =
      (f[1][0][0][p] + f[1][0][1][p] + f[1][1][0][p] + f[1][1][1][p]) % P;
  printf("%lld\n", (res % P + P) % P);
}
int main() {
  read(n);
  read(p);
  init();
  for (int i = 1; i <= n; ++i) read(tp[i]);
  work();
  return 0;
}
