#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 55;
long long f[maxn][maxn][maxn][maxn];
long long pw[maxn];
int c[maxn];
void init() {
  f[0][0][0][0] = 1;
  pw[0] = 1;
  for (int i = 1; i < maxn; i++) pw[i] = (pw[i - 1] * 2ll) % mod;
}
long long cal(int x, bool xx) { return x ? pw[x - 1] : xx; }
void cal_ans(int ew, int ow, int eb, int ob, int now, long long& ret) {
  if (now != 0 && ew)
    (ret += f[ew - 1][ow][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 0) %
            mod) %= mod;
  if (now != 0 && ow)
    (ret += f[ew][ow - 1][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 1) %
            mod) %= mod;
  if (now != 1 && eb)
    (ret += f[ew][ow][eb - 1][ob] * pw[eb + ob - 1 + ew] % mod * cal(ow, 0) %
            mod) %= mod;
  if (now != 1 && ob)
    (ret += f[ew][ow][eb][ob - 1] * pw[eb + ob - 1 + ew] % mod * cal(ow, 1) %
            mod) %= mod;
}
int main(int argc, const char** argv) {
  init();
  int n, p;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) scanf("%d", c + i);
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int ew = 0; ew <= i; ew++)
      for (int ow = 0; ow + ew <= i; ow++)
        for (int eb = 0; ow + ew + eb <= i; eb++) {
          int ob = i - ow - ew - eb;
          cal_ans(ew, ow, eb, ob, c[i], f[ew][ow][eb][ob]);
          if (i == n && ((ow + ob) & 1) == p) (ans += f[ew][ow][eb][ob]) %= mod;
        }
  cout << ans << endl;
  return 0;
}
