#include <bits/stdc++.h>
using namespace std;
const int N = 52, mod = 1e9 + 7;
int c[N], dp[N][N][N], power[N];
inline long long mul(int a, int b) { return 1LL * a * b % mod; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, p;
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> c[i];
  dp[0][0][0] = 1;
  power[0] = 1;
  for (int i = 1; i < N; i++) power[i] = 2LL * power[i - 1] % mod;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i; j++)
      for (int k = 0; k + j <= i; k++) {
        if (c[i - 1] != 1) {
          long long ways = 0;
          if (j) {
            if (k == 0)
              ways = power[i - 1];
            else
              ways = power[i - 2];
            dp[i][j][k] += mul(ways, dp[i - 1][j - 1][k]), dp[i][j][k] %= mod;
          }
          if (k == 0)
            ways = 0;
          else
            ways = power[i - 2];
          dp[i][j][k] += mul(ways, dp[i - 1][j][k]), dp[i][j][k] %= mod;
        }
        if (c[i - 1] != 0) {
          long long ways = 0;
          if (k) {
            if (j == 0)
              ways = power[i - 1];
            else
              ways = power[i - 2];
            dp[i][j][k] += mul(ways, dp[i - 1][j][k - 1]) % mod,
                dp[i][j][k] %= mod;
          }
          if (j == 0)
            ways = 0;
          else
            ways = power[i - 2];
          dp[i][j][k] += mul(ways, dp[i - 1][j][k]) % mod, dp[i][j][k] %= mod;
        }
      }
  int ans = 0;
  for (int j = 0; j <= n; j++)
    for (int k = 0; k + j <= n; k++)
      if ((k + j) % 2 == p) ans += dp[n][j][k], ans %= mod;
  cout << ans << endl;
}
