#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e16;
long long int mod = 1e9 + 7;
char en = '\n';
long long int abs1(long long int x) {
  if (x < 0) return -x;
  return x;
}
long long int power(long long int x, long long int n, long long int mod) {
  long long int res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
long long int dp[55][55][55][55];
long long int arr[55];
long long int pow2[55];
vector<long long int> choices[55];
long long int myPow(long long int a, long long int n, long long int flag) {
  if (n < 0) {
    return flag;
  }
  return pow2[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(dp, 0, sizeof(dp));
  pow2[0] = 1;
  for (long long int i = 1; i < 55; i++) {
    pow2[i] = (pow2[i - 1] * 2) % mod;
  }
  long long int n;
  long long int p;
  cin >> n >> p;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] != -1)
      choices[i].push_back(arr[i]);
    else {
      choices[i].push_back(0);
      choices[i].push_back(1);
    }
  }
  dp[0][0][0][0] = 1;
  for (long long int i = 1; i <= n; i++) {
    for (long long int bo = 0; bo <= i; bo++) {
      for (long long int be = 0; be <= i - bo; be++) {
        for (long long int wo = 0; wo <= i - bo - be; wo++) {
          long long int we = i - bo - be - wo;
          for (long long int type : choices[i]) {
            if (type == 1) {
              if ((wo - 1) >= 0) {
                dp[i][bo][be][wo] += pow2[be + wo + we - 1] *
                                     dp[i - 1][bo][be][wo - 1] % mod *
                                     myPow(2, bo - 1, 1) % mod;
                if (dp[i][bo][be][wo] >= mod) dp[i][bo][be][wo] -= mod;
              }
              if ((we - 1) >= 0) {
                dp[i][bo][be][wo] += pow2[be + wo + we - 1] *
                                     dp[i - 1][bo][be][wo] % mod *
                                     myPow(2, bo - 1, 0) % mod;
                if (dp[i][bo][be][wo] >= mod) dp[i][bo][be][wo] -= mod;
              }
            } else {
              if ((bo - 1) >= 0) {
                dp[i][bo][be][wo] += pow2[we + bo + be - 1] *
                                     dp[i - 1][bo - 1][be][wo] % mod *
                                     myPow(2, wo - 1, 1) % mod;
                if (dp[i][bo][be][wo] >= mod) dp[i][bo][be][wo] -= mod;
              }
              if ((be - 1) >= 0) {
                dp[i][bo][be][wo] += pow2[we + bo + be - 1] *
                                     dp[i - 1][bo][be - 1][wo] % mod *
                                     myPow(2, wo - 1, 0) % mod;
                if (dp[i][bo][be][wo] >= mod) dp[i][bo][be][wo] -= mod;
              }
            }
          }
        }
      }
    }
  }
  long long int res = 0;
  for (long long int bo = 0; bo <= n; bo++) {
    for (long long int be = 0; be <= n - bo; be++) {
      for (long long int wo = 0; wo <= n - bo - be; wo++) {
        long long int we = n - bo - be - wo;
        long long int parity = (bo & 1) ^ (wo & 1);
        if (parity == p) res += dp[n][bo][be][wo];
        if (res >= mod) res -= mod;
      }
    }
  }
  cout << res << en;
  return 0;
}
