#include <bits/stdc++.h>
using namespace std;
long long Count[52 + 1][52 + 1][52 + 1][52 + 1];
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  int c[n + 2];
  for (int i = 0; i < n; ++i) scanf("%d", &c[i]);
  long long ans = 0;
  Count[0][0][0][0] = 1;
  for (int be = 0; be <= n; ++be)
    for (int we = 0; we + be <= n; ++we)
      for (int bo = 0; bo + be + we <= n; ++bo)
        for (int wo = 0; bo + be + we + wo <= n; ++wo) {
          int i = be + we + bo + wo;
          if (c[i] != 0) {
            long long s = i ? ((1LL << (i - 1)) % 1000000007LL) : 1;
            if (bo) {
              Count[be][we + 1][bo][wo] += 1LL * Count[be][we][bo][wo] * s;
              Count[be][we + 1][bo][wo] %= 1000000007LL;
            } else
              s = (1LL << i) % 1000000007LL;
            Count[be][we][bo][wo + 1] += 1LL * Count[be][we][bo][wo] * s;
            Count[be][we][bo][wo + 1] %= 1000000007LL;
          }
          if (c[i] != 1) {
            long long s = i ? ((1LL << (i - 1)) % 1000000007LL) : 1;
            if (wo) {
              Count[be + 1][we][bo][wo] += 1LL * Count[be][we][bo][wo] * s;
              Count[be + 1][we][bo][wo] %= 1000000007LL;
            } else
              s = (1LL << i) % 1000000007LL;
            Count[be][we][bo + 1][wo] += 1LL * Count[be][we][bo][wo] * s;
            Count[be][we][bo + 1][wo] %= 1000000007LL;
          }
          if (i == n && ((bo + wo) & 1) == p) {
            ans += Count[be][we][bo][wo];
            ans %= 1000000007LL;
          }
        }
  printf("%lld\n", ans);
  return 0;
}
