#include <bits/stdc++.h>
using namespace std;
const int INFL = (int)1e9;
const long long int INFLL = (long long int)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
namespace mod_op {
const long long int MOD = (long long int)1e9 + 7;
class modll {
 private:
  long long int val;
  inline long long int modify(long long int x) {
    long long int ret = x % MOD;
    if (ret < 0) ret += MOD;
    return ret;
  }
  inline long long int inv(long long int x) {
    if (x == 0)
      return 1 / x;
    else if (x == 1)
      return 1;
    else
      return modify(inv(MOD % x) * modify(-MOD / x));
  }

 public:
  modll(long long int init = 0) {
    val = modify(init);
    return;
  }
  modll(const modll &another) {
    val = another.val;
    return;
  }
  inline modll &operator=(const modll &another) {
    val = another.val;
    return *this;
  }
  inline modll operator+(const modll &x) { return (val + x.val) % MOD; }
  inline modll operator-(const modll &x) { return (val - x.val) % MOD; }
  inline modll operator*(const modll &x) { return (val * x.val) % MOD; }
  inline modll operator/(const modll &x) { return (val * inv(x.val)) % MOD; }
  inline modll &operator+=(const modll &x) {
    val = (val + x.val) % MOD;
    return *this;
  }
  inline modll &operator-=(const modll &x) {
    val = (val - x.val) % MOD;
    return *this;
  }
  inline modll &operator*=(const modll &x) {
    val = (val * x.val) % MOD;
    return *this;
  }
  inline modll &operator/=(const modll &x) {
    val = (val * inv(x.val)) % MOD;
    return *this;
  }
  inline bool operator==(const modll &x) { return val == x.val; }
  inline bool operator!=(const modll &x) { return val != x.val; }
  friend inline istream &operator>>(istream &is, modll &x) {
    is >> x.val;
    return is;
  }
  friend inline ostream &operator<<(ostream &os, modll &x) {
    os << x.val;
    return os;
  }
  long long int get_val() { return val; }
};
modll pow(modll n, long long int p) {
  modll ret;
  if (p == 0)
    ret = 1;
  else if (p == 1)
    ret = n;
  else {
    ret = pow(n, p / 2);
    ret *= ret;
    if (p % 2 == 1) ret *= n;
  }
  return ret;
}
vector<modll> facts;
inline void make_facts(int n) {
  if (facts.empty()) facts.push_back(modll(1));
  for (int i = facts.size(); i <= n; ++i)
    facts.push_back(modll(facts.back() * (long long int)i));
  return;
}
vector<modll> ifacts;
vector<modll> invs;
inline void make_invs(int n) {
  if (invs.empty()) {
    invs.push_back(modll(0));
    invs.push_back(modll(1));
  }
  for (int i = invs.size(); i <= n; ++i) {
    invs.push_back(invs[(int)MOD % i] * ((int)MOD - (int)MOD / i));
  }
  return;
}
inline void make_ifacts(int n) {
  make_invs(n);
  if (ifacts.empty()) ifacts.push_back(modll(1));
  for (int i = ifacts.size(); i <= n; ++i)
    ifacts.push_back(modll(ifacts.back() * invs[i]));
  return;
}
modll combination(long long int n, long long int r) {
  if (n >= r && r >= 0) {
    modll ret;
    make_facts((int)n);
    make_ifacts((int)n);
    ret = facts[(unsigned)n] * ifacts[(unsigned)r] * ifacts[(unsigned)(n - r)];
    return ret;
  } else
    return 0;
}
modll get_fact(long long int n) {
  make_facts((int)n);
  return facts[(int)n];
}
long long int disc_log(modll a, modll b) {
  long long int ret = -1;
  long long int m = ((long long int)sqrt((double)MOD) +
                     ((long long int)MOD <= (long long int)sqrt((double)MOD) *
                                                (long long int)sqrt((double)MOD)
                          ? 0
                          : 1));
  unordered_map<long long int, long long int> mp;
  modll x = 1;
  for (int i = 0; i < (int)m; i++) {
    mp[x.get_val()] = i;
    x *= a;
  }
  x = modll(1) / pow(a, m);
  modll k = b;
  for (int i = 0; i < (int)m; i++) {
    if (mp.find(k.get_val()) == mp.end())
      k *= x;
    else {
      ret = i * m + mp[k.get_val()];
      break;
    }
  }
  return ret;
}
}  // namespace mod_op
using namespace mod_op;
const int N = 51;
const int NN = N * N;
const int NNN = NN * N;
int index(int i, int ew, int ow, int eb) {
  return i * NNN + ew * NN + ow * N + eb;
}
int main() {
  int n;
  cin >> n;
  int p;
  cin >> p;
  vector<int> colors(n);
  for (int i = 0; i < (int)n; i++) cin >> colors[i];
  vector<modll> dp(NNN * N);
  for (int i = 0; i < (int)N; i++) {
    for (int ew = 0; ew < (int)N; ew++) {
      for (int ow = 0; ow < (int)N; ow++) {
        for (int eb = 0; eb < (int)N; eb++) {
          dp[index(i, ew, ow, eb)] = 0;
        }
      }
    }
  }
  modll divided_combination_sum[N][2];
  for (int i = 0; i < (int)N; i++) {
    divided_combination_sum[i][0] = 0;
    divided_combination_sum[i][1] = 0;
    for (int j = 0; j < (int)i + 1; j++) {
      divided_combination_sum[i][j % 2] += combination(i, j);
    }
  }
  if (colors[0] == -1 || colors[0] == 0) {
    dp[index(1, 0, 1, 0)] = 1;
  }
  if (colors[0] == -1 || colors[0] == 1) {
    dp[index(1, 0, 0, 0)] = 1;
  }
  for (int i = 1; i <= (int)n - 1; i++) {
    for (int ew = 0; ew < (int)N; ew++) {
      if (i - ew < 0) break;
      for (int ow = 0; ow < (int)N; ow++) {
        if (i - ew - ow < 0) break;
        for (int eb = 0; eb < (int)N; eb++) {
          int ob = i - ew - ow - eb;
          if (ob < 0) break;
          if (colors[i] == -1 || colors[i] == 0) {
            dp[index(i + 1, ew, ow + 1, eb)] += dp[index(i, ew, ow, eb)] *
                                                pow((modll)2, ew + ow + eb) *
                                                divided_combination_sum[ob][0];
            dp[index(i + 1, ew + 1, ow, eb)] += dp[index(i, ew, ow, eb)] *
                                                pow((modll)2, ew + ow + eb) *
                                                divided_combination_sum[ob][1];
          }
          if (colors[i] == -1 || colors[i] == 1) {
            dp[index(i + 1, ew, ow, eb)] += dp[index(i, ew, ow, eb)] *
                                            pow((modll)2, eb + ob + ew) *
                                            divided_combination_sum[ow][0];
            dp[index(i + 1, ew, ow, eb + 1)] += dp[index(i, ew, ow, eb)] *
                                                pow((modll)2, eb + ob + ew) *
                                                divided_combination_sum[ow][1];
          }
        }
      }
    }
  }
  modll ans = 0;
  for (int ew = 0; ew < (int)N; ew++) {
    if (n - ew < 0) break;
    for (int ow = 0; ow < (int)N; ow++) {
      if (n - ew - ow < 0) break;
      for (int eb = 0; eb < (int)N; eb++) {
        int ob = n - ew - ow - eb;
        int type = (ow + ob) % 2;
        if (p == type) ans += dp[index(n, ew, ow, eb)];
      }
    }
  }
  cout << ans << endl;
}
