#include <bits/stdc++.h>
using namespace std;
const long long int MAX_N = 2e5, inf = 1e9, mod = 1e9 + 7;
long long int a[55], dp[55][55][55][55] = {};
int32_t main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  long long int pt[100] = {1};
  for (long long int i = 1; i < 100; i++) pt[i] = (pt[i - 1] * 2) % mod;
  long long int n, p;
  cin >> n >> p;
  dp[0][0][0][0] = 1;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i <= n; i++) {
    for (long long int ew = 0; ew <= i; ew++) {
      for (long long int ow = 0; ow <= i; ow++) {
        for (long long int eb = 0; eb <= i; eb++) {
          long long int ob = i - ew - ow - eb - 1;
          if (ob < 0) continue;
          long long int r = 0;
          if (a[i] != 1) {
            r = ob + eb + ew;
            if (ow) r += ow - 1;
            dp[i][ew][ow][eb] =
                (dp[i][ew][ow][eb] + dp[i - 1][ew][ow][eb] * (pt[r]) % mod) %
                mod;
            if (ow)
              dp[i][ew][ow][eb + 1] = (dp[i][ew][ow][eb + 1] +
                                       dp[i - 1][ew][ow][eb] * (pt[r]) % mod) %
                                      mod;
          }
          if (a[i] != 0) {
            r = ew + ow + eb;
            if (ob) r += ob - 1;
            dp[i][ew][ow + 1][eb] =
                (dp[i][ew][ow + 1][eb] + dp[i - 1][ew][ow][eb] * pt[r] % mod) %
                mod;
            if (ob)
              dp[i][ew + 1][ow][eb] = (dp[i][ew + 1][ow][eb] +
                                       dp[i - 1][ew][ow][eb] * (pt[r]) % mod) %
                                      mod;
          }
        }
      }
    }
  }
  long long int ans = 0;
  for (long long int ew = 0; ew <= n; ew++) {
    for (long long int ow = 0; ow <= n; ow++) {
      for (long long int eb = 0; eb <= n; eb++) {
        long long int ob = n - ew - ow - eb;
        if (ob < 0) continue;
        if ((ob + ow) % 2 == p) {
          ans += dp[n][ew][ow][eb];
          ans %= mod;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
