#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int n, p, c[55], dp[55][55][55][55], nCk[55][55], sum[55][55], sum2[55];
void add(int &x, int y) {
  x += y, x %= mod;
  if (x < 0) x += mod;
}
int main() {
  for (int i = 0; i <= 50; ++i) {
    nCk[i][i] = nCk[i][0] = 1;
  }
  for (int i = 2; i <= 50; ++i) {
    for (int j = 1; j < i; ++j) {
      nCk[i][j] = (nCk[i - 1][j - 1] + nCk[i - 1][j]) % mod;
    }
  }
  for (int i = 0; i <= 50; ++i) {
    for (int j = 0; j <= 50; ++j) {
      sum[i][j] = ((j > 1 ? sum[i][j - 2] : 0) + nCk[i][j]) % mod;
    }
    sum2[i] = (i == 0 ? 1 : 2ll * sum2[i - 1] % mod);
  }
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  if (c[1] == -1)
    dp[1][1][0][0] = dp[1][0][0][1] = 1;
  else if (c[1] == 0)
    dp[1][1][0][0] = 1;
  else
    dp[1][0][0][1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int bo = 0; bo <= n; ++bo) {
      for (int be = 0; be <= n; ++be) {
        for (int wo = 0; wo <= n; ++wo) {
          if (bo + be + wo > i) break;
          int we = i - bo - be - wo;
          if (c[i] == -1 || c[i] == 0) {
            if (bo > 0) {
              int tmp =
                  1ll * dp[i - 1][bo - 1][be][wo] * sum[wo][wo - wo % 2] % mod;
              tmp = 1ll * tmp * sum2[we + be + bo - 1] % mod;
              add(dp[i][bo][be][wo], tmp);
            }
            if (be > 0 && wo > 0) {
              int tmp = 01ll * dp[i - 1][bo][be - 1][wo] *
                        sum[wo][wo - (wo % 2 == 0)] % mod;
              tmp = 1ll * tmp * sum2[we + bo + be - 1] % mod;
              add(dp[i][bo][be][wo], tmp);
            }
          }
          if (c[i] == -1 || c[i] == 1) {
            if (wo > 0) {
              int tmp =
                  1ll * dp[i - 1][bo][be][wo - 1] * sum[bo][bo - bo % 2] % mod;
              tmp = 1ll * tmp * sum2[be + we + wo - 1] % mod;
              add(dp[i][bo][be][wo], tmp);
            }
            if (we > 0 && bo > 0) {
              int tmp = 1ll * dp[i - 1][bo][be][wo] *
                        sum[bo][bo - (bo % 2 == 0)] % mod;
              tmp = 1ll * tmp * sum2[be + wo + we - 1] % mod;
              add(dp[i][bo][be][wo], tmp);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int bo = 0; bo <= n; ++bo) {
    for (int be = 0; be <= n; ++be) {
      for (int wo = 0; wo <= n; ++wo) {
        if ((bo + wo) % 2 == p) {
          add(ans, dp[n][bo][be][wo]);
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}
