#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const long long maxn = 52, MOD = (1000000007);
long long dp[maxn][maxn][maxn][maxn], C[maxn], tav[400];
long long p, ans, n;
long long sum(long long a, long long b) {
  a = (a + b) % MOD;
  return a;
}
long long mul(long long a, long long b) {
  a = (a * b) % MOD;
  return a;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  tav[0] = 1;
  for (long long i = 1; i < 300; i++) {
    tav[i] = (tav[i - 1] * 2ll) % MOD;
  }
  cin >> n >> p;
  for (long long i = 0; i < n; i++) {
    cin >> C[i];
  }
  dp[0][0][0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long fb = 0; fb < n; fb++) {
      for (long long zb = 0; zb < n; zb++) {
        for (long long fw = 0; fw < n; fw++) {
          long long zw = i - 1 - (fb + zb + fw);
          if (zw < 0) continue;
          if (C[i - 1] == -1 || C[i - 1] == 1) {
            long long zar = tav[fb + zb + zw];
            if (fw != 0) zar = mul(zar, tav[fw - 1]);
            if (10 != 1)
              dp[i][fb + 1][zb][fw] =
                  sum(dp[i][fb + 1][zb][fw], mul(dp[i - 1][fb][zb][fw], zar));
            if (fw != 0)
              dp[i][fb][zb + 1][fw] =
                  sum(dp[i][fb][zb + 1][fw], mul(dp[i - 1][fb][zb][fw], zar));
          }
          if (C[i - 1] == -1 || C[i - 1] == 0) {
            long long zar = tav[fw + zw + zb];
            if (fb != 0) zar = mul(zar, tav[fb - 1]);
            if (10 != 1)
              dp[i][fb][zb][fw + 1] =
                  sum(dp[i][fb][zb][fw + 1], mul(dp[i - 1][fb][zb][fw], zar));
            if (fb != 0)
              dp[i][fb][zb][fw + 0] =
                  sum(dp[i][fb][zb][fw + 0], mul(dp[i - 1][fb][zb][fw], zar));
          }
        }
      }
    }
  }
  for (long long i = 0; i <= n; i++)
    for (long long j = 0; j <= n; j++)
      for (long long k = 0; k <= n; k++) {
        if (i + j + k > n) continue;
        if ((i + k) % 2 != p) continue;
        ans = sum(ans, dp[n][i][j][k]);
      }
  cout << ans;
  return 0;
}
