#include <bits/stdc++.h>
using namespace std;
const int maxn = 51;
const int lbt = 1e9 + 7;
void init(int n);
int C[maxn][maxn];
int pow2[maxn];
int f[maxn];
int dp[maxn][maxn][maxn];
int a[maxn];
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  init(n);
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= i; k++) {
        if (!dp[i][j][k]) continue;
        if (a[i + 1] == 1 || a[i + 1] == -1) {
          dp[i + 1][j][k] += (long long)pow2[i - k] * (pow2[k] - f[k]) % lbt *
                             dp[i][j][k] % lbt;
          if (dp[i + 1][j][k] < 0) dp[i + 1][j][k] += lbt;
          if (dp[i + 1][j][k] >= lbt) dp[i + 1][j][k] -= lbt;
          dp[i + 1][j + 1][k] +=
              (long long)pow2[i - k] * f[k] % lbt * dp[i][j][k] % lbt;
          if (dp[i + 1][j + 1][k] >= lbt) dp[i + 1][j + 1][k] -= lbt;
        }
        if (a[i + 1] == 0 || a[i + 1] == -1) {
          dp[i + 1][j][k] += (long long)pow2[i - j] * (pow2[j] - f[j]) % lbt *
                             dp[i][j][k] % lbt;
          if (dp[i + 1][j][k] < 0) dp[i + 1][j][k] += lbt;
          if (dp[i + 1][j][k] >= lbt) dp[i + 1][j][k] -= lbt;
          dp[i + 1][j][k + 1] +=
              (long long)pow2[i - j] * f[j] % lbt * dp[i][j][k] % lbt;
          if (dp[i + 1][j][k + 1] >= lbt) dp[i + 1][j][k + 1] -= lbt;
        }
      }
    }
  }
  if (p == 1) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        if ((i + j) % 2) {
          ans += dp[n][i][j];
          if (ans >= lbt) ans -= lbt;
        }
      }
    }
    printf("%d", ans);
  } else {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        if ((i + j) % 2 == 0) {
          ans += dp[n][i][j];
          if (ans >= lbt) ans -= lbt;
        }
      }
    }
    printf("%d", ans);
  }
  return 0;
}
void init(int n) {
  for (int i = 0; i <= n; i++) {
    C[i][0] = 1;
    C[i][i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] >= lbt) C[i][j] -= lbt;
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j % 2 == 0) {
        f[i] += C[i][j];
        if (f[i] >= lbt) f[i] -= lbt;
      }
    }
  }
  pow2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pow2[i] = pow2[i - 1] * 2;
    if (pow2[i] >= lbt) pow2[i] -= lbt;
  }
}
