#include <bits/stdc++.h>
using namespace std;
const int MAXN = 59, mod = 1e9 + 7;
int n, p;
int a[MAXN];
long long pp[MAXN], dp[MAXN][2][2][2];
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  pp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pp[i] = pp[i - 1] * 2 % mod;
    if (i == 1) {
      if (a[i] == 0)
        dp[i][1][0][1] = 1;
      else if (a[i] == 1)
        dp[i][0][1][1] = 1;
      else
        dp[i][1][0][1] = dp[i][0][1][1] = 1;
      continue;
    }
    if (a[i] == 0) {
      dp[i][1][0][0] = dp[i - 1][1][0][1] * pp[i - 1] % mod;
      dp[i][1][0][1] = dp[i - 1][1][0][0] * pp[i - 1] % mod;
      dp[i][1][1][0] = (dp[i - 1][0][1][1] * pp[i - 2] % mod +
                        dp[i - 1][1][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                       mod;
      dp[i][1][1][1] = (dp[i - 1][0][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                       mod;
      dp[i][0][1][0] = (dp[i - 1][0][1][0] * pp[i - 2] % mod) % mod;
      dp[i][0][1][1] = (dp[i - 1][0][1][1] * pp[i - 2] % mod) % mod;
    } else if (a[i] == 1) {
      dp[i][0][1][0] = dp[i - 1][0][1][1] * pp[i - 1] % mod;
      dp[i][0][1][1] = dp[i - 1][0][1][0] * pp[i - 1] % mod;
      dp[i][1][1][0] = (dp[i - 1][1][0][1] * pp[i - 2] % mod +
                        dp[i - 1][1][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                       mod;
      dp[i][1][1][1] = (dp[i - 1][1][0][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                       mod;
      dp[i][1][0][0] = (dp[i - 1][1][0][0] * pp[i - 2] % mod) % mod;
      dp[i][1][0][1] = (dp[i - 1][1][0][1] * pp[i - 2] % mod) % mod;
    } else {
      dp[i][1][0][0] = dp[i - 1][1][0][1] * pp[i - 1] % mod;
      dp[i][1][0][1] = dp[i - 1][1][0][0] * pp[i - 1] % mod;
      dp[i][1][1][0] = (dp[i - 1][0][1][1] * pp[i - 2] % mod +
                        dp[i - 1][1][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                       mod;
      dp[i][1][1][1] = (dp[i - 1][0][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][0] * pp[i - 2] % mod +
                        dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                       mod;
      dp[i][0][1][0] = (dp[i - 1][0][1][0] * pp[i - 2] % mod) % mod;
      dp[i][0][1][1] = (dp[i - 1][0][1][1] * pp[i - 2] % mod) % mod;
      dp[i][0][1][0] += dp[i - 1][0][1][1] * pp[i - 1] % mod,
          dp[i][0][1][0] %= mod;
      dp[i][0][1][1] += dp[i - 1][0][1][0] * pp[i - 1] % mod,
          dp[i][0][1][1] %= mod;
      dp[i][1][1][0] += (dp[i - 1][1][0][1] * pp[i - 2] % mod +
                         dp[i - 1][1][1][0] * pp[i - 2] % mod +
                         dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                        mod,
          dp[i][1][1][0] %= mod;
      dp[i][1][1][1] += (dp[i - 1][1][0][0] * pp[i - 2] % mod +
                         dp[i - 1][1][1][0] * pp[i - 2] % mod +
                         dp[i - 1][1][1][1] * pp[i - 2] % mod) %
                        mod,
          dp[i][1][1][1] %= mod;
      dp[i][1][0][0] += (dp[i - 1][1][0][0] * pp[i - 2] % mod) % mod,
          dp[i][1][0][0] %= mod;
      dp[i][1][0][1] += (dp[i - 1][1][0][1] * pp[i - 2] % mod) % mod,
          dp[i][1][0][1] %= mod;
    }
  }
  printf("%lld\n", (dp[n][1][1][p] + dp[n][1][0][p] + dp[n][0][1][p]) % mod);
  return 0;
}
