#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int N = 1 << 6, M = 1e9 + 7;
int dp[N][2][2][2];
int c[N], q[N];
template <class T>
void add(T& a, const T& b) {
  a += b;
  if (M <= a) a -= M;
}
int mult(const int& a, ll b) { return a * b % M; }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  short p;
  cin >> n >> p;
  for (int i = 1; i <= n; ++i) cin >> c[i];
  q[0] = 1;
  for (auto i = (1); i < (N); ++i) {
    q[i] = (q[i - 1] << 1) % M;
  }
  int res = 0;
  dp[0][0][0][0] = 1;
  for (int i = 1, cur = 1; i <= n; ++i, cur ^= 1) {
    for (auto w1 = (0); w1 < (2); ++w1) {
      for (auto b1 = (0); b1 < (2); ++b1) {
        for (auto parity = (0); parity < (2); ++parity) {
          auto& x = dp[cur][w1][b1][parity];
          x = 0;
          if (c[i] != 1) {
            add(x, mult(dp[!cur][w1][b1][parity], w1 ? q[i - 2] : 0));
            if (b1)
              add(x, mult(dp[!cur][w1][0][!parity] + dp[!cur][w1][1][!parity],
                          w1 ? q[i - 2] : q[i - 1]));
          }
          if (c[i] != 0) {
            add(x, mult(dp[!cur][w1][b1][parity], b1 ? q[i - 2] : 0));
            if (w1)
              add(x, mult(dp[!cur][0][b1][!parity] + dp[!cur][1][b1][!parity],
                          b1 ? q[i - 2] : q[i - 1]));
          }
          if (i == n && p == parity) add(res, x);
        }
      }
    }
  }
  cout << res;
}
