#include <bits/stdc++.h>
using namespace std;
int n, p;
long long m = 1e9 + 7;
long long p2[52];
int memo[52][52][52][52], c[52];
int numpos(int use, int ow, int ew, int ob) {
  if (use == 1) {
    if (c[1] == -1 && (ow || ob)) return 1;
    if (c[1] == 1 && ob) return 1;
    if (c[1] == 0 && ow) return 1;
    return 0;
  }
  if (memo[use][ow][ew][ob] != -1) return memo[use][ow][ew][ob];
  int eb = use - ew - ow - ob;
  long long ans = 0, trm;
  if (c[use] <= 0) {
    int prev = ow + ew - 1;
    if (ow) {
      if (ob <= 1)
        trm = 1;
      else
        trm = p2[ob - 1];
      trm = (trm * p2[eb]) % m;
      trm = (trm * p2[prev]) % m;
      ans = (ans + trm * numpos(use - 1, ow - 1, ew, ob)) % m;
    }
    if (ew && ob) {
      trm = (p2[ob - 1] * p2[eb]) % m;
      trm = (trm * p2[prev]) % m;
      ans = (ans + trm * numpos(use - 1, ow, ew - 1, ob)) % m;
    }
  }
  if (c[use]) {
    int prev = ob + eb - 1;
    if (ob) {
      if (ow <= 1)
        trm = 1;
      else
        trm = p2[ow - 1];
      trm = (trm * p2[ew]) % m;
      trm = (trm * p2[prev]) % m;
      ans = (ans + trm * numpos(use - 1, ow, ew, ob - 1)) % m;
    }
    if (eb && ow) {
      trm = (p2[ow - 1] * p2[ew]) % m;
      trm = (trm * p2[prev]) % m;
      ans = (ans + trm * numpos(use - 1, ow, ew, ob)) % m;
    }
  }
  return memo[use][ow][ew][ob] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  memset(memo, -1, sizeof memo);
  p2[0] = 1;
  for (int i = 1; i <= 51; ++i) {
    p2[i] = (p2[i - 1] * 2) % m;
  }
  cin >> n >> p;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }
  long long ans = 0;
  for (int ow = 0; ow <= n; ++ow) {
    for (int ew = 0; ew + ow <= n; ++ew) {
      for (int ob = 0; ob + ow + ew <= n; ++ob) {
        if ((ob + ow) % 2 != p) continue;
        ans = (ans + numpos(n, ow, ew, ob)) % m;
      }
    }
  }
  cout << ans;
  return 0;
}
