#include <bits/stdc++.h>
using namespace std;
int n, a[55], p;
int dp[55][55][55][55], ans;
int two[55];
int T(int x, int y) {
  if (x == 0) {
    if (y)
      return 0;
    else
      return 1;
  }
  return two[x - 1];
}
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  two[0] = 1;
  for (int i = 1; i <= n; i++) two[i] = 2ll * two[i - 1] % 1000000007;
  dp[0][0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k <= j; k++) {
        for (int l = 0; l <= i - 1 - j; l++) {
          if (!dp[i - 1][j][k][l]) continue;
          if (a[i] != 0) {
            (dp[i][j + 1][k + 1][l] += 1ll * dp[i - 1][j][k][l] * T(l, 0) %
                                       1000000007 * two[i - 1 - l] %
                                       1000000007) %= 1000000007;
            (dp[i][j + 1][k][l] += 1ll * dp[i - 1][j][k][l] * T(l, 1) %
                                   1000000007 * two[i - 1 - l] % 1000000007) %=
                1000000007;
          }
          if (a[i] != 1) {
            (dp[i][j][k][l + 1] += 1ll * dp[i - 1][j][k][l] * T(k, 0) %
                                   1000000007 * two[i - 1 - k] % 1000000007) %=
                1000000007;
            (dp[i][j][k][l] += 1ll * dp[i - 1][j][k][l] * T(k, 1) % 1000000007 *
                               two[i - 1 - k] % 1000000007) %= 1000000007;
          }
        }
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= n - i; k++) {
        int op = (j + k) % 2;
        if (op == p) (ans += dp[n][i][j][k]) %= 1000000007;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
