#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int M = 1e9 + 7;
long long ans = 0, odd[maxn], even[maxn], c[maxn][maxn], _pow[maxn];
long long dp[maxn][maxn][maxn][maxn];
void init() {
  _pow[0] = 1;
  for (int i = 0; i < maxn; ++i) {
    c[i][0] = c[i][i] = 1;
    if (i) _pow[i] = (_pow[i - 1] * 2) % M;
  }
  for (int i = 1; i < maxn; ++i)
    for (int j = 0; j < i; ++j) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % M;
    }
  for (int i = 0; i < maxn; ++i) {
    for (int j = 0; j <= i; j += 2) {
      even[i] = (even[i] + c[i][j]) % M;
    }
    for (int j = 1; j <= i; j += 2) {
      odd[i] = (odd[i] + c[i][j]) % M;
    }
  }
}
void solve(int ow, int ew, int ob, int eb, int n) {
  if (n != 0 && ow != 0)
    dp[ow][ew][ob][eb] =
        (dp[ow][ew][ob][eb] +
         dp[ow - 1][ew][ob][eb] * _pow[ow + ew + eb - 1] % M * even[ob]) %
        M;
  if (n != 0 && ew != 0)
    dp[ow][ew][ob][eb] =
        (dp[ow][ew][ob][eb] +
         dp[ow][ew - 1][ob][eb] * _pow[ow + ew + eb - 1] % M * odd[ob]) %
        M;
  if (n != 1 && ob != 0)
    dp[ow][ew][ob][eb] =
        (dp[ow][ew][ob][eb] +
         dp[ow][ew][ob - 1][eb] * _pow[ob + eb + ew - 1] % M * even[ow]) %
        M;
  if (n != 1 && eb != 0)
    dp[ow][ew][ob][eb] =
        (dp[ow][ew][ob][eb] +
         dp[ow][ew][ob][eb - 1] * _pow[ob + eb + ew - 1] % M * odd[ow]) %
        M;
}
int main() {
  init();
  int n, p, a[maxn];
  dp[0][0][0][0] = 1;
  cin >> n >> p;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i)
    for (int ow = 0; ow <= i; ++ow)
      for (int ew = 0; ew + ow <= i; ++ew)
        for (int ob = 0; ob + ew + ow <= i; ++ob) {
          int eb = i - ow - ew - ob;
          solve(ow, ew, ob, eb, a[i]);
          if (i == n && ((ob + ow) & 1) == p)
            ans = (ans + dp[ow][ew][ob][eb]) % M;
        }
  cout << ans << endl;
}
