#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
  return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
template <typename T>
T getnum() {
  int sign = 1;
  T ret = 0;
  char c;
  do {
    c = getchar();
  } while (c == ' ' || c == '\n');
  if (c == '-')
    sign = -1;
  else
    ret = c - '0';
  while (1) {
    c = getchar();
    if (c < '0' || c > '9') break;
    ret = 10 * ret + c - '0';
  }
  return sign * ret;
}
inline void ini(int& x) { x = getnum<int>(); }
inline void scani(int& x) { scanf("%d", &x); }
const int N = 55;
const long long MOD = 1e9 + 7;
inline long long addmod(long long a, long long b) { return (a + b) % MOD; }
inline long long submod(long long a, long long b) {
  return (MOD + a - b) % MOD;
}
inline long long mulmod(long long a, long long b) { return (a * b) % MOD; }
int pow2[N];
int n, p;
int arr[N];
int dp[N][N][N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pow2[0] = 1;
  for (int i = 1; i <= N - 1; i += 1) pow2[i] = mulmod(pow2[i - 1], 2);
  cin >> n >> p;
  for (int i = 1; i <= n; i += 1) cin >> arr[i];
  int ans = 0;
  dp[0][0][0][0] = 1;
  for (int i = 1; i <= n; i += 1) {
    for (int c0p0 = 0; c0p0 <= i - 1; c0p0 += 1) {
      for (int c0p1 = 0; c0p1 <= i - 1 - c0p0; c0p1 += 1) {
        for (int c1p0 = 0; c1p0 <= i - 1 - c0p0 - c0p1; c1p0 += 1) {
          if (dp[i - 1][c0p0][c0p1][c1p0] == 0) continue;
          int c1p1 = i - 1 - c0p0 - c0p1 - c1p0;
          int ways = dp[i - 1][c0p0][c0p1][c1p0];
          ways = mulmod(ways, pow2[c0p0]);
          ways = mulmod(ways, pow2[c1p0]);
          if (arr[i] == 0 || arr[i] == -1) {
            int nways = mulmod(ways, pow2[c0p1]);
            int ways0, ways1;
            if (c1p1 > 0)
              ways0 = ways1 = mulmod(nways, pow2[c1p1 - 1]);
            else {
              ways1 = nways;
              ways0 = 0;
            }
            dp[i][c0p0 + 1][c0p1][c1p0] =
                addmod(dp[i][c0p0 + 1][c0p1][c1p0], ways0);
            dp[i][c0p0][c0p1 + 1][c1p0] =
                addmod(dp[i][c0p0][c0p1 + 1][c1p0], ways1);
          }
          if (arr[i] == 1 || arr[i] == -1) {
            int nways = mulmod(ways, pow2[c1p1]);
            int ways0, ways1;
            if (c0p1 > 0)
              ways0 = ways1 = mulmod(nways, pow2[c0p1 - 1]);
            else {
              ways1 = nways;
              ways0 = 0;
            }
            dp[i][c0p0][c0p1][c1p0 + 1] =
                addmod(dp[i][c0p0][c0p1][c1p0 + 1], ways0);
            dp[i][c0p0][c0p1][c1p0] = addmod(dp[i][c0p0][c0p1][c1p0], ways1);
          }
        }
      }
    }
  }
  for (int i = 0; i <= n; i += 1) {
    for (int j = 0; j <= n - i; j += 1) {
      for (int k = 0; k <= n - i - j; k += 1) {
        if ((n - i - k) % 2 != p) continue;
        ans = addmod(ans, dp[n][i][j][k]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
