#include <bits/stdc++.h>
using namespace std;
int col[55];
long long dp[55][55][55][55];
long long inv[55], fact[55], pw[55], odd[55], even[55];
long long fastpow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = (ret * x) % (1000 * 1000 * 1000 + 7);
    x = (x * x) % (1000 * 1000 * 1000 + 7);
    y >>= 1;
  }
  return ret;
}
long long C(int x, int y) {
  return fact[x] * inv[y] % (1000 * 1000 * 1000 + 7) * inv[x - y] %
         (1000 * 1000 * 1000 + 7);
}
void preprocess() {
  pw[0] = inv[0] = fact[0] = 1;
  for (int i = 1; i < 55; i++) {
    pw[i] = (pw[i - 1] * 2LL) % (1000 * 1000 * 1000 + 7);
    fact[i] = (fact[i - 1] * i) % (1000 * 1000 * 1000 + 7);
    inv[i] = fastpow(fact[i], (1000 * 1000 * 1000 + 7) - 2);
  }
  for (int i = 0; i < 55; i++) {
    for (int j = 0; j <= i; j += 2)
      even[i] = (even[i] + C(i, j)) % (1000 * 1000 * 1000 + 7);
    for (int j = 1; j <= i; j += 2)
      odd[i] = (odd[i] + C(i, j)) % (1000 * 1000 * 1000 + 7);
  }
}
void find_ans(int i, int ow, int ew, int eb, int ob, long long &ret) {
  if (col[i] != 0 && ow != 0)
    ret = (ret + dp[i - 1][ow - 1][ew][eb] * pw[ow - 1 + ew + eb] %
                     (1000 * 1000 * 1000 + 7) * even[ob] %
                     (1000 * 1000 * 1000 + 7)) %
          (1000 * 1000 * 1000 + 7);
  if (col[i] != 0 && ew != 0)
    ret = (ret + dp[i - 1][ow][ew - 1][eb] * pw[ow + ew - 1 + eb] %
                     (1000 * 1000 * 1000 + 7) * odd[ob] %
                     (1000 * 1000 * 1000 + 7)) %
          (1000 * 1000 * 1000 + 7);
  if (col[i] != 1 && ob != 0)
    ret = (ret + dp[i - 1][ow][ew][eb] * pw[ob - 1 + eb + ew] %
                     (1000 * 1000 * 1000 + 7) * even[ow] %
                     (1000 * 1000 * 1000 + 7)) %
          (1000 * 1000 * 1000 + 7);
  if (col[i] != 1 && eb != 0)
    ret = (ret + dp[i - 1][ow][ew][eb - 1] * pw[ob + eb - 1 + ew] %
                     (1000 * 1000 * 1000 + 7) * odd[ow] %
                     (1000 * 1000 * 1000 + 7)) %
          (1000 * 1000 * 1000 + 7);
}
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", col + i);
  preprocess();
  long long ans = 0;
  dp[0][0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int ow = 0; ow <= n; ow++) {
      for (int ew = 0; ew <= n; ew++) {
        for (int eb = 0; eb <= n; eb++) {
          int ob = i - ow - ew - eb;
          find_ans(i, ow, ew, eb, ob, dp[i][ow][ew][eb]);
          if (n == i && (ow + ob) % 2 == p)
            ans = (ans + dp[i][ow][ew][eb]) % (1000 * 1000 * 1000 + 7);
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
